版本
1.5.6
使用Ribbon zuul hystrix
引入重试jar包
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
参考 LoadBalancerAutoConfiguration 以及RibbonAutoConfiguration
实现原理: RetryLoadBalancerInterceptor 实现 ClientHttpRequestInterceptor 通过拦截器实现
配置
| 属性 | 值 | 描述 | 默认值 |
|---|---|---|---|
| spring.cloud.loadbalancer.retry.enabled | ture | 开启重试机制 | true |
| zuul.retryable | true | 如果使用zuul,需要配置该属性 | false |
| hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds | 8000 | 如果使用ribbon和hystrix,设置超时时间 | 1000 |
| ribbon.OkToRetryOnAllOperations | true | 是否所有的操作都重试 | false |
| ribbon.MaxAutoRetriesNextServer | 2 | 重试负载均衡其他实例的最大重试次数,不包括首次实例 | 0 |
| ribbon.MaxAutoRetries | 0 | 同一台实例的最大重试次数,不包括首次调用 | 0 |
| ribbon.ConnectTimeout | 1000 | http建立socket超时时间 | |
| ribbon.ReadTimeout | 3000 | http读取响应socket超时时间 |
注意:
- ribbon.ConnectTimeout+ribbon.ReadTimeout<hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds
- 连接失败的意思是服务宕机,请求不可到达, 并不是服务报错
本文介绍了在Spring Cloud中进行请求服务失败时的重试配置。针对1.5.6版本,详细讲解了如何引入重试相关的jar包,并提供了配置示例。重试机制通过拦截器实现,旨在处理服务宕机导致的连接失败问题,确保请求的高可用性。
788

被折叠的 条评论
为什么被折叠?



