I have a Spring Integration Batch job which is triggerred when the files are arrived:
@Bean
public IntegrationFlow fileTriggeredIntegrationFlow() {
return IntegrationFlows.from(fileReadingMessageSource(),
c -> c.poller(Pollers.fixedRate(filePollerFrequency, filePollerInitialDelay)))
.transform(toJobLaunchRequest())
.handle(jobLaunchingGateway)
.handle("jobCompletionHandler", "afterJob")
.get();
}
@Bean
public FileReadingMessageSource fileReadingMessageSource() {
FileReadingMessageSource sourceReader = new FileReadingMessageSource();
log.info("Listening for {} files at {}", sourceFilePattern, sourceFileDirectory);
sourceReader.setDirectory(new File(sourceFileDirectory));
sourceReader.setFilter(new RegexPatternFileListFilter(sourceFilePattern));
return sourceReader;
}
It has been pretty smooth for long but recently I faced issue where the jobs ran twice for the same input file. Following is a snippet from log files:
2018-12-06 13:52:32,595 INFO [task-scheduler-7] o.s.i.f.FileReadingMessageSource:380 - Created message: [GenericMessage [payload=/local/MY_INPUT_FILE.DAT, headers={id=ba1ad258-72cf-ed07-1175-3d1cc36f9bc1, timestamp=1544122352595}]]
2018-12-06 13:52:32,599 INFO [task-scheduler-10] o.s.i.f.FileReadingMessageSource:380 - Created message: [GenericMessage [payload=/local/MY_INPUT_FILE.DAT, headers={id=ab8e9fbc-72a1-43e0-2ca3-8b8dcb3d91e5, timestamp=1544122352599}]]
If you see there are two threads marked in bold which have picked up the same files and triggered same job twice. Can someone please guide me how to avoid these cases?