@Bean
@LoadBalanced
RestTemplate restTemplate() {
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
httpRequestFactory.setReadTimeout(5000);
httpRequestFactory.setConnectTimeout(5000);
return new RestTemplate(httpRequestFactory);
}
package feign;
import static java.util.concurrent.TimeUnit.SECONDS;
/**
* Cloned for each invocation to {@link Client#execute(Request, feign.Request.Options)}.
* Implementations may keep state to determine if retry operations should continue or not.
*/
public interface Retryer extends Cloneable {
/**
* if retry is permitted, return (possibly after sleeping). Otherwise propagate the exception.
*/
void continueOrPropagate(RetryableException e);
Retryer clone();
public static class Default implements Retryer {
private final int maxAttempts;
private final long period;
private final long maxPeriod;
int attempt;
long sleptForMillis;
public Default() {
this(100, SECONDS.toMillis(1), 5);
}
public Default(long period, long maxPeriod, int maxAttempts) {
this.period = period;
this.maxPeriod = maxPeriod;
this.maxAttempts = maxAttempts;
this.attempt = 1;
}
@Bean
Retryer feignRetryer() {
return Retryer.NEVER_RETRY;
}
@Bean
Request.Options requestOptions(ConfigurableEnvironment env){
int ribbonReadTimeout = env.getProperty("ribbon.ReadTimeout", int.class, 6000);
int ribbonConnectionTimeout = env.getProperty("ribbon.ConnectTimeout", int.class, 3000);
return new Request.Options(ribbonConnectionTimeout, ribbonReadTimeout);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
simpleClientHttpRequestFactory.setConnectTimeout(1000);
simpleClientHttpRequestFactory.setReadTimeout(1000);
return new RestTemplate(simpleClientHttpRequestFactory);
}
spring: cloud: loadbalancer: retry: enabled: true ribbon: # 同一实例最大重试次数,不包括首次调用 MaxAutoRetries: 1 # 重试其他实例的最大重试次数,不包括首次所选的server MaxAutoRetriesNextServer: 2 # 是否所有操作都进行重试 OkToRetryOnAllOperations: false
ribbon: MaxAutoRetries: 1 MaxAutoRetriesNextServer: 2 OkToRetryOnAllOperations: false
zuul: # 开启Zuul的重试 retryable: true ribbon: MaxAutoRetries: 1 MaxAutoRetriesNextServer: 2 OkToRetryOnAllOperations: false
zuul.routes.<routename>.retryable=true
clientName: ribbon: retryableStatusCodes: 404,502
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有