最近在生产环境中出现配置了ribbon的重试参数,但是没有生效,表现就是下游服务上线的过程中,上游服务总是拿到超时降级的错误码,配置如下:
hystrix:
threadpool:
group:
coreSize: 20
maximumSize: 100
allowMaximumSizeToDivergeFromCoreSize: true
maxQueueSize: 200
queueSizeRejectionThreshold: 200
command:
key:
execution:
timeout:
enabled: true
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 500
interruptOnTimeout: true
interruptOnFutureCancel: false
semaphore:
maxConcurrentRequests: 5000
feign:
client:
config:
default:
connectTimeout: 500
readTimeout: 3000
hystrix:
enabled: true
ribbon:
eager-load:
enable: true
MaxAutoRetries: 0
MaxAutoRetriesNextServer: 2
retryableStatusCodes: 500,502,504
OkToRetryOnAllOperations: true
先说明一下ribbon的配置:
MaxAutoRetries:同一台服务器上的最大重试次数(不包括第一次尝试),默认值0;
MaxAutoRetriesNextServer:要重试的下一个服务器的最大数量(不包括第一个服务器),默认值1;
retryableStatusCodes:可以根据接口返回的状态码判断是否重试其他服务
OkToRetryOnAllOperations:每个操作都开启重试机制,默认false(只有GET请求才会重试,true:GET、POST、PUT等所有请求都会重试)
经过一番排查和搜索,查到如下结论:
1.feign的读超时时间readTimeout必须要小于hystrix的超时时间timeoutInMilliseconds,才会重试。上面的配置前者是3000,后者是500,一旦触发超时降级,就不会重试,hystrix的超时是最高优先级,如果在重试期间,时间超过了hystrix的超时时间,会立即熔断。
2.feign底层是ribbon,但feign优先级高于ribbon。
将feign的readTimeout设置为500,hystrix的timeoutInMilliseconds设置成1000即可。
Author:忆之独秀
Email:leaguenew@qq.com
转载注明出处:https://blog.csdn.net/lavorange/article/details/105895764