我的用例如下:Spring集成正在监听一些文件夹。添加文件时,它运行spring batch,文件名为param。如果ExecutionListener.afterJob
上的作业失败,则fileInputAdapter将被停止(fileInputAdapter.stop());
。之后将发送coll fileInputAdapter.start();
下一个文件。但对于我的情况是nasser启动批处理具有相同的失败文件。
<int:channel id="fileInputChannel"></int:channel>
<int:inbound-channel-adapter id="fileInputAdapter" ref="fileReadingMessageAdapter" method="receive" channel="fileInputChannel" auto-startup="true">
<int:poller fixed-rate="1000"/>
</int:inbound-channel-adapter>
@Configuration
@IntegrationComponentScan
@EnableIntegration
public class IntegrationConfig {
@Bean
@ServiceActivator(inputChannel = "errorChannel", outputChannel = "nullChanel")
protected ErrorLogger errorLogger(JobLauncher jobLauncher) {
return new ErrorLogger();
}
@Bean
@ServiceActivator(inputChannel = "jobChannel", outputChannel = "errorChannel")
protected JobLaunchingMessageHandler launcher(JobLauncher jobLauncher) {
return new JobLaunchingMessageHandler(jobLauncher);
}
@Transformer(inputChannel = "fileInputChannel", outputChannel = "jobChannel")
public JobLaunchRequest transform(File aFile) {
String fileName = aFile.getAbsolutePath();
JobParameters jobParameters = new JobParametersBuilder().addString("input.file.name", fileName)
.toJobParameters();
logger.warn("JobLaunchRequest for file :" + fileName);
JobLaunchRequest request = new JobLaunchRequest(job, jobParameters);
return request;
}
}
@Component
public class FileReadingMessageAdapter extends FileReadingMessageSource {
@Autowired
public FileReadingMessageAdapter(ConcurrentMetadataStore metadataStore) {
super(Comparator.comparing(File::getName));
final CompositeFileListFilter<File> compositeFileListFilter = new CompositeFileListFilter<>();
FileSystemPersistentAcceptOnceFileListFilter perstFilter = new FileSystemPersistentAcceptOnceFileListFilter(
metadataStore, "");
compositeFileListFilter.addFilter(perstFilter);
compositeFileListFilter.addFilter(new SimplePatternFileListFilter("*.txt"));
compositeFileListFilter.addFilter(new LastModifiedFileListFilter(3));
this.setFilter(compositeFileListFilter);
this.setDirectory(new File("tempDropFolder"));
//this.setDirectory(new File("C:/Temp/myfiles/"));
this.setScanEachPoll(true);
this.setUseWatchService(true);
}
}
@Component
public class ExecutionListener implements JobExecutionListener {
private @Autowired SourcePollingChannelAdapter fileInputAdapter;
@Override
public void afterJob(JobExecution jobExecution) {
List<Throwable> allFailureExceptions = jobExecution.getAllFailureExceptions();
ExitStatus es = jobExecution.getExitStatus();
BatchStatus status = jobExecution.getStatus();
if (jobExecution.getStatus().equals(BatchStatus.FAILED)) {
fileInputAdapter.stop();
}
答案 0 :(得分:0)
不确定什么是“nasser”,但如果您在问题中编辑和修复语法,那就太棒了。
您使用FileSystemPersistentAcceptOnceFileListFilter
后不应该发生什么。
另一方面,你有几个问题:
FileReadingMessageSource
?标准版有什么问题?另外:如果您使用LastModifiedFileListFilter
,则应考虑将其放在合并的开头,然后切换到ChainFileListFilter
:https://docs.spring.io/spring-integration/docs/5.0.6.RELEASE/reference/html/files.html#file-reading