定制化一个超时重试机制
/**
* 重试策略 默认 重试间隔1500毫秒 最大间隔时间4秒 重试3次
*/
@Slf4j
public class CommonFeignRetry extends Retryer.Default {
public CommonFeignRetry() {
this(1500, 4000, 3);
}
public CommonFeignRetry(long period, long maxPeriod, int maxAttempts) {
super(period, maxPeriod, maxAttempts);
}
@Override
public void continueOrPropagate(RetryableException e) {
log.warn("Feign重试,详情:{}", e.getMessage());
super.continueOrPropagate(e);
}
@Override
public Retryer clone() {
return new CommonFeignRetry();
}
}
案例:针对feignClient2配置超时重试机制
feign:
client:
config:
default:
loggerLevel: full
connectTimeout: 10000
readTimeout: 10000
# 针对feignClient2配置超时重试机制
feignClient2:
connectTimeout: 2000
readTimeout: 2000
retryer: com.immotors.core.config.CommonFeignRetry