zuul开启重试机制

部分引用自网络,


image.png

配置文件需要开启重试
spring.cloud.loadbalancer.retry.enabled=true --- 此处测试发现无效,需要单独配置zuul开启,配置方式如下
zuul:
retryable: true
默认为false
同时需要引入jar
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=10000

hello-service.ribbon.ConnectTimeout=250
hello-service.ribbon.ReadTimeout=1000
hello-service.ribbon.OkToRetryOnAllOperations=true
hello-service.ribbon.MaxAutoRetriesNextServer=2
hello-service.ribbon.MaxAutoRetries=1


其他次要信息
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds:断路器的超时时间需要大于ribbon的超时时间,不然不会触发重试。


【此处添加hello-service为服务名局部配置,不加则为全局配置】
hello-service.ribbon.ConnectTimeout:请求连接的超时时间

hello-service.ribbon.ReadTimeout:请求处理的超时时间

hello-service.ribbon.OkToRetryOnAllOperations:对所有操作请求都进行重试

hello-service.ribbon.MaxAutoRetriesNextServer:切换实例的重试次数

hello-service.ribbon.MaxAutoRetries:对当前实例的重试次数

根据如上配置,当访问到故障请求的时候,它会再尝试访问一次当前实例(次数由MaxAutoRetries配置),如果不行,就换一个实例进行访问,如果还是不行,再换一次实例访问(更换次数由MaxAutoRetriesNextServer配置),如果依然不行,返回失败信息

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。