时间:2021-05-02
首先声明一点,这里的重试并不是报错以后的重试,而是负载均衡客户端发现远程请求实例不可到达后,去重试其他实例。
? 1 2 3 4 5 6 7 8 @bean @loadbalanced resttemplate resttemplate() { httpcomponentsclienthttprequestfactory httprequestfactory = new httpcomponentsclienthttprequestfactory(); httprequestfactory.setreadtimeout(5000); httprequestfactory.setconnecttimeout(5000); return new resttemplate(httprequestfactory); }
feign重试机制
feign默认是通过自己包下的retryer进行重试配置,默认是5次
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 package feign; import static java.util.concurrent.timeunit.seconds; /** * cloned for each invocation to {@link client#execute(request, feign.request.options)}. * implementations may keep state to determine if retry operations should continue or not. */ public interface retryer extends cloneable { /** * if retry is permitted, return (possibly after sleeping). otherwise propagate the exception. */ void continueorpropagate(retryableexception e); retryer clone(); public static class default implements retryer { private final int maxattempts; private final long period; private final long maxperiod; int attempt; long sleptformillis; public default() { this(100, seconds.tomillis(1), 5); } public default(long period, long maxperiod, int maxattempts) { this.period = period; this.maxperiod = maxperiod; this.maxattempts = maxattempts; this.attempt = 1; }feign取消重试
? 1 2 3 4 @bean retryer feignretryer() { return retryer.never_retry; }feign请求超时设置
? 1 2 3 4 5 6 7 @bean request.options requestoptions(configurableenvironment env){ int ribbonreadtimeout = env.getproperty("ribbon.readtimeout", int.class, 6000); int ribbonconnectiontimeout = env.getproperty("ribbon.connecttimeout", int.class, 3000); return new request.options(ribbonconnectiontimeout, ribbonreadtimeout); }以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://www.cnblogs.com/zhangjianbin/p/7228606.html
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
SpringCloud重试机制配置首先声明一点,这里的重试并不是报错以后的重试,而是负载均衡客户端发现远程请求实例不可到达后,去重试其他实例。@Bean@Loa
当我们调用接口的时候由于网络原因可能失败,再尝试就成功了,这就是重试机制。非幂等的情况下要小心使用重试。tips:幂等性HTTP/1.1中对幂等性的定义是:一次
SpringCloud是现在流行的分布式服务框架,它提供了很多有用的组件。比如:配置中心、Eureka服务发现、消息总线、熔断机制等。配置中心在SpringCl
这篇文章主要介绍了SpringCloud应用实现配置自动刷新过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以
背景:Springcloud项目使用Springcloud-config作为分布式配置,配置参数都放在config里,不同的环境有不同的问题:项目本地:boos