spring cloud 请求服务失败, 重试配置

来源:互联网 发布:凯佰赫战盾数据 编辑:程序博客网 时间:2024/06/06 03:13

版本

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
- 连接失败的意思是服务宕机,请求不可到达, 并不是服务报错

原创粉丝点击