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 重试解析的更多相关文章

  1. SpringCloud Feign重试详解

    摘要: 今天在生产环境发生了数据库进程卡死的现象,除了sql因为全量更新,没加索引的原因,最主要还是我们的接口的服务器端接口出现问题了.忽视了更新接口的幂等性,以及调用方feign client的重试 ...

  2. 一文详解Spring Cloud Feign重试机制

    前言 Feign组件默认使用Ribbon的重试机制并增加了根据状态码判断重试机制,默认情况下是不启用的.Feign使用的是Spring Retry组件,需要引入依赖才能启用. 一.POM引入Sprin ...

  3. 修改Feign数据解析,由jackson改为fastjson,同时解决fastjson中Content-Type问题

    https://my.oschina.net/u/3419586/blog/2964047 背景:在用Feign Client 接口调用,由于jackson对null等特殊值处理存在异常,故改用fas ...

  4. Feign 系列(05)Spring Cloud OpenFeign 源码解析

    Feign 系列(05)Spring Cloud OpenFeign 源码解析 [TOC] Spring Cloud 系列目录(https://www.cnblogs.com/binarylei/p/ ...

  5. Feign 系列(04)Contract 源码解析

    Feign 系列(04)Contract 源码解析 [TOC] Spring Cloud 系列目录(https://www.cnblogs.com/binarylei/p/11563952.html# ...

  6. 【Feign/Ribbon】记录一次生产上的SpringCloudFeign的重试问题

    在上周在的微供有数项目中(数据产品),需要对接企业微信中第三方应用,在使用Feign的去调用微服务的用户模块用微信的code获取access_token以及用户工厂信息时出现Feign重试超时报错的情 ...

  7. SpringCloud-技术专区-从源码层面让你认识Feign工作流程和运作机制

    Feign工作流程源码解析 什么是feign:一款基于注解和动态代理的声明式restful http客户端. 原理 Feign发送请求实现原理 微服务启动类上标记@EnableFeignClients ...

  8. 不使用SpringBoot如何将原生Feign集成到Spring中来简化http调用

    在微服务架构中,如果使用得是SpringCloud,那么只需要集成SpringFeign就可以了,SpringFeign可以很友好的帮我们进行服务请求,对象解析等工作. 然而SpingCloud是依赖 ...

  9. Feign get接口传输对象引发一场追寻

    一个报错引发的追寻之路: Feign get接口传输对象,调用方接口代码: @FeignClient(name = "manage") public interface Acces ...

随机推荐

  1. c# mvc 封装返回对象

    将所有返回JsonContent对象进行再次封装 public class ResultFilterAttribute : System.Web.Mvc.ActionFilterAttribute { ...

  2. 开源自己写的Library到github,让别人或自己的项目依赖

    对于不会git命令的自己,要上传项目或libary,看了本文,傻瓜式操作,绝壁简单! 新建一个空白工程 File-->New-->New module-->Android Libra ...

  3. k8s 组件介绍__单Master集群部署

    参考链接:https://github.com/opsnull/follow-me-install-kubernetes-cluster kubernetes 概述 1.kubernetes 是什么 ...

  4. Python(可变/不可变类型,list,tuple,dict,set)

    补充:(可用操作技巧) >>> x=900 >>> y=900 >>> x==y True >>> type(x) is typ ...

  5. react学习笔记2之正确使用状态

    //状态不要直接修改,比如: // 错的,这样写不会重新渲染组件 this.state.comment = 'Hello'; //修改状态正确的方式 this.setState({comment:'H ...

  6. [HDFS Manual] CH6 HDFS Federation

    HDFS Federation HDFS Federation 1 Background 2.多个namenode/namespace 2.1 关键好处 3 联合配置 3.1 配置 3.2 格式化na ...

  7. Open Cygwin at a specific folder

    转自:https://stackoverflow.com/questions/9637601/open-cygwin-at-a-specific-folder# When you install Cy ...

  8. 通过jQuery实时监听表格行数变化

    [本文出自天外归云的博客园] 使用bootstrap table组件,当使用过滤器的时候,页面的表格行数发生变化,此时需要统计表格行数.想要监听表格变化,如何做呢? 使用场景:有一个表格里放着许多测试 ...

  9. Object type TYPE failed to create with error

    ORA-39083: Object type TYPE failed to create with error: ORA-02304: invalid object identifier litera ...

  10. java语言的优缺点

    转载自:https://blog.csdn.net/bingshanyijiao_fkx/article/details/51613954 角度一: 优点:简单.安全.稳定.跨平台 缺点:需要运行环境 ...