分享免费的编程资源和教程

网站首页 > 技术教程 正文

spring-retry重试机制 spring batch retry

goqiw 2024-09-25 20:13:11 技术教程 41 ℃ 0 评论

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.retry.backoff.FixedBackOffPolicy;

import org.springframework.retry.policy.SimpleRetryPolicy;

import org.springframework.retry.support.RetryTemplate;


@Configuration

public class RetryTemplateConfig {

/**

* 微信群发重试间隔为1min

*/

private static final long BACK_OFF = 1;

private static final int RETRY_ATTEMPTS = 2;

@Bean

public RetryTemplate retryTemplate() {

RetryTemplate retryTemplate = new RetryTemplate();

FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();

fixedBackOffPolicy.setBackOffPeriod(BACK_OFF);

retryTemplate.setBackOffPolicy(fixedBackOffPolicy);

SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();

retryPolicy.setMaxAttempts(RETRY_ATTEMPTS);

retryTemplate.setRetryPolicy(retryPolicy);

return retryTemplate;

}

}

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表