Spring 批处理:需要更好的作业配置
Spring Batch: Need a better job configuration
我的 Spring 批处理应用程序处理 5 种不同类型文件中的 1 种。所有 5 种类型的流程完全相同。我的配置相当长且笨拙。有人可以通过重用流程帮助我压缩一些吗?
这是我能想到的最好的:
return jobBuilderFactory.get(CommonConstants.BATCH_JOB_DISTRIBUTION)
.listener(jobListener)
.start(retrieveFileStep())
.next(createFileJobDetailStep(fileJobDetailTasklet))
.next(fileTypeDecider)
.from(fileTypeDecider).on(FileType.YearEnd.name()).to(yearEndStep)
.from(yearEndStep).on("ERROR").to(moveFileToErrorStep(fileOperationsTasklet))
.from(yearEndStep).on("SUCCESS").to(moveFileToProcessedStep(fileOperationsTasklet))
.from(fileTypeDecider).on(FileType.Quarterly.name()).to(quarterlyStep)
.from(quarterlyStep).on("ERROR").to(moveFileToErrorStep(fileOperationsTasklet))
.from(quarterlyStep).on("SUCCESS").to(moveFileToProcessedStep(fileOperationsTasklet))
//[repeat 3 more times...]
我希望有更好的写法。谢谢
我最终创建了一个子流程,并在整个作业配置中重复使用该子流程。
public Flow flow(String flowName, Step step, Tasklet fileOperationsTasklet) {
return new FlowBuilder<Flow>(flowName)
.start(step)
.from(step).on("ERROR").to(moveFileToErrorStep(fileOperationsTasklet))
.from(step).on("SUCCESS").to(moveFileToProcessedStep(fileOperationsTasklet))
.end();
}
所以现在我的配置包括:
.from(fileTypeDecider).on(FileType.YearEnd.name()).to(flow("yearEndFlow", yearEndStep, fileOperationsTasklet))
我的 Spring 批处理应用程序处理 5 种不同类型文件中的 1 种。所有 5 种类型的流程完全相同。我的配置相当长且笨拙。有人可以通过重用流程帮助我压缩一些吗?
这是我能想到的最好的:
return jobBuilderFactory.get(CommonConstants.BATCH_JOB_DISTRIBUTION)
.listener(jobListener)
.start(retrieveFileStep())
.next(createFileJobDetailStep(fileJobDetailTasklet))
.next(fileTypeDecider)
.from(fileTypeDecider).on(FileType.YearEnd.name()).to(yearEndStep)
.from(yearEndStep).on("ERROR").to(moveFileToErrorStep(fileOperationsTasklet))
.from(yearEndStep).on("SUCCESS").to(moveFileToProcessedStep(fileOperationsTasklet))
.from(fileTypeDecider).on(FileType.Quarterly.name()).to(quarterlyStep)
.from(quarterlyStep).on("ERROR").to(moveFileToErrorStep(fileOperationsTasklet))
.from(quarterlyStep).on("SUCCESS").to(moveFileToProcessedStep(fileOperationsTasklet))
//[repeat 3 more times...]
我希望有更好的写法。谢谢
我最终创建了一个子流程,并在整个作业配置中重复使用该子流程。
public Flow flow(String flowName, Step step, Tasklet fileOperationsTasklet) {
return new FlowBuilder<Flow>(flowName)
.start(step)
.from(step).on("ERROR").to(moveFileToErrorStep(fileOperationsTasklet))
.from(step).on("SUCCESS").to(moveFileToProcessedStep(fileOperationsTasklet))
.end();
}
所以现在我的配置包括:
.from(fileTypeDecider).on(FileType.YearEnd.name()).to(flow("yearEndFlow", yearEndStep, fileOperationsTasklet))