我正在尝试使用Spring Integration with Spring batch。我正在将消息Message转换为JobLaunchRequest
public class FileMessageToJobRequest {
private Job job;
private String fileParameterName;
public void setFileParameterName(String fileParameterName) {
this.fileParameterName = fileParameterName;
}
public void setJob(Job job) {
this.job = job;
}
public JobLaunchRequest toRequest(Message<File> message) throws IOException {
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
String fileName = message.getPayload().getName();
String currentDateTime = LocalDateTime.now().toString();
logger.info("currentDateTime"+currentDateTime);
jobParametersBuilder.addString(this.fileName, fileName);
jobParametersBuilder.addString(this.currentDateTime, currentDateTime);
return new JobLaunchRequest(job, jobParametersBuilder.toJobParameters());
}
}
这是我的整合流程
return IntegrationFlows.
from(Files.inboundAdapter(new File("landing"))
.preventDuplicates() .patternFilter("*.txt")
, e -> e.poller(Pollers.fixedDelay(2500) .maxMessagesPerPoll(15)
.taskExecutor(getFileProcessExecutor())))
.transform(fileMessageToJobRequest)
.handle(jobLaunchingGw(jobLauncher)).get();
@Bean
public MessageHandler jobLaunchingGw(JobLauncher jobLauncher)
{
return new JobLaunchingGateway(jobLauncher);
}
由于某种原因,如果两个文件打印相同的currentDateTime,则两个打印相同时间的文件之一不会被处理。文件最有可能同时出现。我使用的是ThreadPoolTaskExecutor corepool size,max池大小,队列容量为15
String currentDateTime = LocalDateTime.now().toString();
文件没有得到处理。我假设这是某种竞争条件。我甚至尝试在JobLaunchRequest上同步。这是竞争条件吗?为什么消息会丢失?
我正在使用Spring Integration 4.2.6所有最新版本(几乎)的Spring。
我对此配置的引用是这个问题 Java DSL config