[英]Implement fault tolerance in Spring Batch
I have following batch job implemented in Spring Batch config: 我在Spring Batch配置中实现了以下批处理作业:
@Bean
public Job myJob(Step step1, Step step2, Step step3) {
return jobs.get("myJob").start(step1).next(step2).next(step3).build();
}
@Bean
public Step step1(ItemReader<String> myReader,
ItemProcessor<String, String> myProcessor,
ItemWriter<String> myWriter) {
return steps.get("step1").<String, String>chunk(1)
.reader(myReader)
.processor(myProcessor)
.writer(myWriter)
.build();
}
I would like to retry the step1 (also step2 and step3 so forth) on certain exception and rollback the job on any failure (also between the retries). 我想在某些异常上重试step1(也是step2和step3),并在任何失败时(也在重试之间)回滚作业。 I understand that rollback is not going to be automatic and I am clear what to rollback for each step with writing custom code.
我知道回滚不会是自动的,我很清楚在编写自定义代码的每一步都要回滚什么。
What is the best way to implement this? 实现这个的最佳方法是什么?
Spring framework provides @Retryable and @Recover annotations to retry and to recover when something fails. Spring框架提供@Retryable和@Recover注释来重试并在出现故障时恢复。 You can check this article.
你可以查看这篇文章。 https://www.baeldung.com/spring-retry
https://www.baeldung.com/spring-retry
Fault tolerance features in Spring Batch are applied to items in chunk-oriented steps, not to the entire step. Spring Batch中的容错功能适用于面向块的步骤中的项目,而不是整个步骤。
What you can try to do is use a flow with a decider where you restart from step1 if an exception occurs in one of the subsequent steps. 您可以尝试做的是使用带有决策程序的流,如果在后续步骤之一中发生异常,则从步骤1重新启动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.