springcloud重试机制

boot版本1.5.8 version Dalston.SR4

1、zuul重试

zuul使用ribbon、使用hystrix

他的重试配置参数如下:

#是否开启重试功能
zuul.retryable=true
#同一个Server重试的次数(除去首次)
ribbon.MaxAutoRetries=3
#切换相同Server的次数
ribbon.MaxAutoRetriesNextServer=0

也可以针对application-name指定服务的重试(这个没测试)

 

2、feign重试

我的版本的hystrix是关闭的不用配置,只用配置ribbon相关参数即可,重试参数ribbon.OkToRetryOnAllOperations

ribbon.ConnectTimeout
请求连接的超时时间

ribbon.ReadTimeout
请求处理的超时时间

ribbon.OkToRetryOnAllOperations
对所有操作请求都进行重试

ribbon.MaxAutoRetriesNextServer
切换实例的重试次数

ribbon.MaxAutoRetries
对当前实例的重试次数

3、resttemple重试:无效

看到spring.cloud.loadbalancer.retry.enabled 用来开启resttemple的重试,测试没用

    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
        httpRequestFactory.setConnectionRequestTimeout(3000);
        httpRequestFactory.setConnectTimeout(3000);
        httpRequestFactory.setReadTimeout(3000);

        return new RestTemplate(httpRequestFactory);
    }

下面会继续测试,持续改进

20181026更新,高版本的spring.cloud.loadbalancer.retry.enabled =true

 

参考博客:http://blog.didispace.com/spring-cloud-zuul-retry-detail/

 

http://www.itmuch.com/spring-cloud-sum/spring-cloud-retry/  总结篇

https://my.oschina.net/sean1989/blog/904016

https://www.cnblogs.com/zhangjianbin/p/7228628.html

以下两篇和我测试结果有些不匹配,再议。

https://mp.weixin.qq.com/s?__biz=MzI2ODYxMjU4MQ==&mid=2247483913&idx=1&sn=a963f061558e4a2f259ed55f4b8f986d&chksm=eaeda483dd9a2d95eb56a47c8404f7158d0a47083fe87bc2004f9e906a78f09f0891da95e57d&mpshare=1&scene=24&srcid=0111ZkRG2NoqYzvoJaZ4YydO#rd
 

https://mp.weixin.qq.com/s?__biz=MzAxODcyNjEzNQ==&mid=2247483671&idx=1&sn=786ce81a2381f4cbecab769148148889&chksm=9bd0ac8faca7259969827258da4f3b52cd1c7000b90647b37aedd2ff267f4da6153564a32467&mpshare=1&scene=24&srcid=0223ECMTDJM4k8Q6X4aXOy8o#rd

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值