Spring Cloud Zuul模块本身就包含了对于hystrix和ribbon的依赖,当我们使用zuul通过path和serviceId的组合来配置路由的时候,可以通过hystrix和ribbon的配置调整路由请求的各种时间超时机制。
1 ribbon配置举例
配置连接超时时间1秒,请求处理时间2秒,统一服务server尝试重连1次,切换server重连1次
1
2
3
4
5
|
ribbon:
ConnectTimeout: 1000
ReadTimeout: 2000
MaxAutoRetries: 1
MaxAutoRetriesNextServer: 1
|
2 hystirx配置举例
1
2
3
4
5
6
7
|
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的重试配置:
1
2
|
zuul:
retryable: true
|
特别注意zuul的重试配置需要依赖spring的retry,不然的话怎么配置都是徒劳
1
2
3
4
|
< dependency >
< groupId >org.springframework.retry</ groupId >
< artifactId >spring-retry</ artifactId >
</ dependency >
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
原文链接:https://segmentfault.com/a/1190000014186143
相关文章
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
-
2025-05-25 38
-
2025-05-27 80
-
2025-05-27 17
-
2025-06-04 85
-
2025-06-04 60