Spring Cloud Zuul的重试配置详解

网友投稿 300 2023-02-09


Spring Cloud Zuul的重试配置详解

Spring Cloud Zuul模块本身就包含了对于hystrix和ribbon的依赖,当我们使用zuul通过path和serviceId的组合来配置路由的时候,可以通过hystrix和rihttp://bbon的配置调整路由请求的各种时间超时机制。

1 ribbon配置举例

配置连接超时时间1秒,请求处理时间2秒,统一服务server尝试重连1次,切换server重连1次

ribbon:

ConnectTimeout: 1000

ReadTimeout: 2000

MaxAutoRetries: 1

MaxAutoRetriesNextServer: 1

2 hystirx配置举例

hystrix:

command:

default:

execution:

isolation:

thread:

timeoutInMilliseconds: 60000

这里需要注意的是hystrix的配置时间应该大于ribbon全部重试时间的总和,上面我配置的是2次重试,包括首次请求,三次时间是6秒

引用官方大神的一段说明

When using Hystrix commands that wrap Ribbon clients you want to make sure your Hystrix timeout is configured to be longer than the configured Ribbon timeout, including any potential

retries that might be made. For example, if your Ribbon connection timeout is one second and

the Ribbon client might retry the request three times, than your Hystrix timeout should

be slightly more than three seconds.

3 打开zuul的重试配置:

zuul:

retryable: true

特别注意zuul的重试配置需要依赖spring的retry,不然的话怎么配置都是徒劳

org.springframework.retry

spring-retry


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:vue todo
下一篇:Spring boot工具类静态属性注入及多环境配置详解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~