摘要:本文主要向大家介绍了JAVA语言之Spring Cloud Zuul的重试配置,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。
本文主要向大家介绍了JAVA语言之Spring Cloud Zuul的重试配置,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。
Spring Cloud Zuul模块本身就包含了对于hystrix和ribbon的依赖,当我们使用zuul通过path和serviceId的组合来配置路由的时候,可以通过hystrix和ribbon的配置调整路由请求的各种时间超时机制。
· 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,不然的话怎么配置都是徒劳
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
以上就是职坐标整理发布关于JAVA的介绍,先祝大家对它有了一定的了解吧,了解更多内容,请关注职坐标编程语言JAVA频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号