【发布时间】:2018-05-19 19:00:26
【问题描述】:
我们使用 spring-batch-integration 来处理目录中的 .json 文件。必须在失败后停止处理,找出问题(更换有问题的文件或其他解决方案)然后继续。当前配置在出错后继续轮询。如何改变它?或者对于这种情况可能有不同的方法。
@Configuration
@IntegrationComponentScan
@EnableIntegration
public class IntegrationConfig {
private @Autowired Job job;
@Bean
@ServiceActivator(inputChannel = "jobChannel",
outputChannel = "errorChannel")
protected JobLaunchingMessageHandler launcher(JobLauncher jobLauncher) {
return new JobLaunchingMessageHandler(jobLauncher);
}
@Bean
public MessageChannel fileInputChannel() {
return new DirectChannel();
}
@Bean
@InboundChannelAdapter(value = "fileInputChannel",
poller = @Poller(fixedDelay = "5000"))
public MessageSource<File> fileReadingMessageSource() {
FileReadingMessageSource source = new FileReadingMessageSource();
source.setDirectory(new File("C:/Temp/myfiles/"));
source.setFilter(new SimplePatternFileListFilter("*.json"));
source.setScanEachPoll(true);
source.setUseWatchService(true);
return source;
}
@Transformer(inputChannel = "fileInputChannel",
outputChannel = "jobChannel")
public JobLaunchRequest transform(File aFile) {
String fileName = aFile.getAbsolutePath();
JobParameters jobParameters =
new JobParametersBuilder().addString("input.file.name", fileName)
.addDate("dateTime", new Date()).toJobParameters();
JobLaunchRequest request = new JobLaunchRequest(job, jobParameters);
return request;
}
}
outputChannel = "nullChannel" 和 outputChannel = "errorChannel" 都没有帮助
【问题讨论】:
标签: spring-integration spring-batch