【发布时间】:2021-06-23 17:38:09
【问题描述】:
我正在尝试在 Spring Batch 中设置 RetryTemplate,我只是找不到有关如何将 RetryTemplate 添加到 StepBuilderFactory 的示例。我发现这个示例可以在 SpringBoot 应用程序中设置它,https://dzone.com/articles/how-to-use-spring-retry-template 但在 Spring Batch 上没有运气。
我尝试使用 RetryTemplate 的原因是设置指数 BackOffPolicy (Spring Batch how to configure retry period for failed jobs)。
我想连接 RetryTemplate 就像设置 RetryTemplate Bean 一样简单,类似的东西(来自@Mahmoud Ben Hassine 的修改代码回答Spring Batch how to configure retry period for failed jobs):
@Bean
public RetryTemplate testExponentialBackoff() throws Exception {
// configure backoff policy
ExponentialBackOffPolicy exponentialBackOffPolicy = new ExponentialBackOffPolicy();
exponentialBackOffPolicy.setInitialInterval(1000);
exponentialBackOffPolicy.setMultiplier(2.0);
exponentialBackOffPolicy.setMaxInterval(10000);
// configure retry policy
SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy();
simpleRetryPolicy.setMaxAttempts(5);
// configure retry template
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setBackOffPolicy(exponentialBackOffPolicy);
retryTemplate.setRetryPolicy(simpleRetryPolicy);
return retryTemplate;
}
我没有找到将它连接到 StepBuilderFactory 的方法。 我想这将类似于“标准”重试:
.faultTolerant()
.retryLimit(3)
.retry(ConnectTimeoutException.class)
有人有关于如何使用 Java 配置进行设置的示例/模板吗?
感谢任何帮助/示例。谢谢,马库斯。
【问题讨论】:
标签: spring spring-batch spring-retry retrypolicy