Feign 重试解析
Spring cloud Feign 在restful 调用失败后,会进行重试。在没有到达指定重试次数,会一直重试。
@Override
public Object invoke(Object[] argv) throws Throwable {
RequestTemplate template = buildTemplateFromArgs.create(argv);
Retryer retryer = this.retryer.clone();
while (true) {
try {
return executeAndDecode(template);
} catch (RetryableException e) {
retryer.continueOrPropagate(e);
if (logLevel != Logger.Level.NONE) {
logger.logRetry(metadata.configKey(), logLevel);
}
continue;
}
}
}
重试策略:
public void continueOrPropagate(RetryableException e) {
if (attempt++ >= maxAttempts) { //1. 超过最大重试次数,直接抛异常。
throw e;
}
long interval;
if (e.retryAfter() != null) {
interval = e.retryAfter().getTime() - currentTimeMillis(); // 重试间隔
if (interval > maxPeriod) {
interval = maxPeriod;
}
if (interval < 0) { //重试间隔到期,立即重试
return;
}
} else {
interval = nextMaxInterval();
}
try {
Thread.sleep(interval); //未到期,线程休眠internal指定的时间
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
sleptForMillis += interval; //统计线程休眠的时间
}
Feign 重试解析的更多相关文章
- SpringCloud Feign重试详解
摘要: 今天在生产环境发生了数据库进程卡死的现象,除了sql因为全量更新,没加索引的原因,最主要还是我们的接口的服务器端接口出现问题了.忽视了更新接口的幂等性,以及调用方feign client的重试 ...
- 一文详解Spring Cloud Feign重试机制
前言 Feign组件默认使用Ribbon的重试机制并增加了根据状态码判断重试机制,默认情况下是不启用的.Feign使用的是Spring Retry组件,需要引入依赖才能启用. 一.POM引入Sprin ...
- 修改Feign数据解析,由jackson改为fastjson,同时解决fastjson中Content-Type问题
https://my.oschina.net/u/3419586/blog/2964047 背景:在用Feign Client 接口调用,由于jackson对null等特殊值处理存在异常,故改用fas ...
- Feign 系列(05)Spring Cloud OpenFeign 源码解析
Feign 系列(05)Spring Cloud OpenFeign 源码解析 [TOC] Spring Cloud 系列目录(https://www.cnblogs.com/binarylei/p/ ...
- Feign 系列(04)Contract 源码解析
Feign 系列(04)Contract 源码解析 [TOC] Spring Cloud 系列目录(https://www.cnblogs.com/binarylei/p/11563952.html# ...
- 【Feign/Ribbon】记录一次生产上的SpringCloudFeign的重试问题
在上周在的微供有数项目中(数据产品),需要对接企业微信中第三方应用,在使用Feign的去调用微服务的用户模块用微信的code获取access_token以及用户工厂信息时出现Feign重试超时报错的情 ...
- SpringCloud-技术专区-从源码层面让你认识Feign工作流程和运作机制
Feign工作流程源码解析 什么是feign:一款基于注解和动态代理的声明式restful http客户端. 原理 Feign发送请求实现原理 微服务启动类上标记@EnableFeignClients ...
- 不使用SpringBoot如何将原生Feign集成到Spring中来简化http调用
在微服务架构中,如果使用得是SpringCloud,那么只需要集成SpringFeign就可以了,SpringFeign可以很友好的帮我们进行服务请求,对象解析等工作. 然而SpingCloud是依赖 ...
- Feign get接口传输对象引发一场追寻
一个报错引发的追寻之路: Feign get接口传输对象,调用方接口代码: @FeignClient(name = "manage") public interface Acces ...
随机推荐
- Spring MVC框架处理Web请求的基本流程
- mysql字符串用法
replace(str,from_str,to_str) --用字符串to_str替换字符串str中的子串from_str并返回 --mysql> select replace('www.mys ...
- 关于expect的实战总结
如何从机器A上ssh到机器B上,然后执行机器B上的命令?如何使之自动化完成?看完下面的文章你就明白了 一.安装 expect 是基于tcl 演变而来的,所以很多语法和tcl 类似 sudo apt-g ...
- MySQL 中的运算符
1.算数运算符 MySQL 支持的算术运算符包括加.减.乘.除和模运算. 运算符 作用 + 加法,获得一个或多个值的和 - 减法,从一个值中减去另一个值 * 乘法,得到两个或多个值的乘积 /,div ...
- TensorFlow精选Github开源项目
转载于:http://www.matools.com/blog/1801988 TensorFlow源码 https://github.com/tensorflow/tensorflow 基于Tens ...
- “5W1H”带你来学习JavaScript
上次的设计模式讲课,从中学习到了非常多.不仅是技术上,更重要的是怎样来学习.我们学习的技术.科技的更新速度超过我们的想象,对于我们这个有生命年限的个体,怎样可以在有生之年可以让自己立足于科技的不败浪潮 ...
- Web API中如何获取相对地址的绝对地址 Server.MapPath
var sPath = System.Web.Hosting.HostingEnvironment.MapPath("/FilePath/");
- 那些好用的Chrome 插件
1. json-viewer 推荐理由:一款Chrome浏览器查看JSON数据自动格式化显示的浏览器插件 https://github.com/tulios/json-viewer
- (转)java术语(PO/POJO/VO/BO/DAO/DTO)
转自:http://blog.csdn.net/gaoyunpeng/article/details/2093211 PO(persistant object) 持久对象在o/r 映射的时候出现的概念 ...
- 【网络编程】——Lighttpd 返回HTTP/1.1 417 Expectation Failed
最近在使用python 的 pcurl 发送 post 请求到服务端的时候[服务端使用的服务是Lighttpd],发现只要 post 请求的数据超过 1024 之后,就会返回如下错误: * Hostn ...