springcloud feign 加上hystrix的流程
一、maven配置
引入feign默认会依赖hystrix,只要不排除就行。 <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-feign</artifactId> <!-- <exclusions>--> <!-- <exclusion>--> <!-- <groupId>io.github.openfeign</groupId>--> <!-- <artifactId>feign-hystrix</artifactId>--> <!-- </exclusion>--> <!-- </exclusions>--></dependency>
application配置开启feign的hystrix配置。
feign.hystrix.enabled=true
二、还是上文那个例子,测试
看到代理对象变为HystrixInvocationHandler,
接着往下调,后面跟单独的feign一样。只是在feignHandler上做了一个包装。
这里要注意,这个线程不是TOMCAT的工作线程,而是使用hystrix中的隔离任务线程池中执行。
正常的线程如下为nio-execute-真正的feign远程接口调用是在hystrix的线程池中。HystrixInvocationHandler.invoke方法为代理方法,最终调用到hystrixCommand.execute()
@Overridepublic Object invoke(final Object proxy, final Method method, final Object[] args)throws Throwable {// early exit if the invoked method is from java.lang.Object// code is the same as ReflectiveFeign.FeignInvocationHandlerif ("equals".equals(method.getName())) {try {Object otherHandler =args.length > 0 && args[0] != null ? Proxy.getInvocationHandler(args[0]) : null;return equals(otherHandler);} catch (IllegalArgumentException e) {return false;}} else if ("hashCode".equals(method.getName())) {return hashCode();} else if ("toString".equals(method.getName())) {return toString();}HystrixCommand<Object> hystrixCommand = new HystrixCommand<Object>(setterMethodMap.get(method)) {@Overrideprotected Object run() throws Exception {try {return HystrixInvocationHandler.this.dispatch.get(method).invoke(args);} catch (Exception e) {throw e;} catch (Throwable t) {throw (Error) t;}}@Overrideprotected Object getFallback() {if (fallbackFactory == null) {return super.getFallback();}try {Object fallback = fallbackFactory.create(getFailedExecutionException());Object result = fallbackMethodMap.get(method).invoke(fallback, args);if (isReturnsHystrixCommand(method)) {return ((HystrixCommand) result).execute();} else if (isReturnsObservable(method)) {// Create a cold Observablereturn ((Observable) result).toBlocking().first();} else if (isReturnsSingle(method)) {// Create a cold Observable as a Singlereturn ((Single) result).toObservable().toBlocking().first();} else if (isReturnsCompletable(method)) {((Completable) result).await();return null;} else {return result;}} catch (IllegalAccessException e) {// shouldn't happen as method is public due to being an interfacethrow new AssertionError(e);} catch (InvocationTargetException e) {// Exceptions on fallback are tossed by Hystrixthrow new AssertionError(e.getCause());}}};if (isReturnsHystrixCommand(method)) {return hystrixCommand;} else if (isReturnsObservable(method)) {// Create a cold Observablereturn hystrixCommand.toObservable();} else if (isReturnsSingle(method)) {// Create a cold Observable as a Singlereturn hystrixCommand.toObservable().toSingle();} else if (isReturnsCompletable(method)) {return hystrixCommand.toObservable().toCompletable();}return hystrixCommand.execute();}
hystrixCommand.execute(),这个就是进入队列,然后在队列进行执行,同步等待。
springcloud feign 加上hystrix的流程相关推荐
- 第七章:SpringCloud Feign对hystrix的支持
方法一:设置fallback属性 Feign Hystrix Fallbacks 官网解释 Hystrix supports the notion of a fallback: a default c ...
- SpringCloud feign、hystrix、zuul超时配置
hystrix超时配置一般需要手动配置,如果不配,接口响应稍慢就会熔断 同样,zuul也有超时配置,feign也有超时配置 zuul配置时,配置如下: hystrix: command: defaul ...
- SpringCloud微服务,euraka、feign、hystrix组件学习
SpringCloud 1 eureka 1.1 eureka基本概念 eureka主要包含两个组件:Eureka Server 和 Eureka Client. eureka server(注册中心 ...
- springcloud+springboot+Eureka+Feign+Ribbon+Hystrix+Zuul
Springcloud集成Eureka Eureka服务端和客户端 本实例采用springboot,eureka和feign/ribbon,hystrix,zuul,mybatis,redis 1. ...
- SpringCloud中 Feign结合Hystrix断路器开发。
Feign结合Hystrix断路器开发: 转载于:https://www.cnblogs.com/longdb/p/10468371.html
- SpringCloud 第十章 Hystrix断路器
一.概述 1.分布式系统面临的问题 分布式系统面临的问题 复杂分布式体系结构中的应用程序有数十个依赖关系,每个依赖关系在某些时候将不可避免地失败. 服务雪崩 多个微服务之间调用的时候,假设微服务A调用 ...
- 【SpringCloud框架之Hystrix断路器】
本笔记内容为尚硅谷SpringCloud框架开发Hystrix部分 目录 一.概述 二.Hystrix重要概念 1.服务降级 2.服务熔断 3.服务限流 三.hystrix案例 1.案例创建和测试 1 ...
- SpringCloud feign 的三种超时时间配置
1.负载均衡 Feign调用服务的默认时长是1秒钟,也就是如果超过1秒没连接上或者超过1秒没响应,就会相应的报错.Feign 的负载均衡底层用的是 Ribbon,其配置如下: ribbon:ReadT ...
- feign整合hystrix:
feign 默认是支持hystrix的, 但是在Spring - cloud Dalston 版本之后就默认关闭了, 因为不一定业务需求要用的到, 所以现在要使用首先得打开他,在yml文件加上如下配置 ...
最新文章
- ios html双击下移,H5页面在ios上双击div,导致屏幕上移的js解决办法
- 关于扁平化视觉设计趋势的一些小分享
- 【OpenCV】OpenCV函数精讲之 -- Mat和IplImage之间的相互装换(OpenCV2.0和OpenCV3.0)
- XP远程桌面连接强制登录
- java heapdump 分析工具_Heapdump分析软件
- 数据结构 | 哈希表与哈希冲突的解决(一)
- Lseg(Language -driven semantic segmentation)
- 2022-2028全球与中国生物基聚氨酯(PU)市场现状及未来发展趋势
- JAVA_协同过滤算法商品推荐
- 第4章 计算机网络自顶向下——网络层:数据平面
- APIAuto——敏捷开发最强大易用的 HTTP 接口工具 (二)
- 在一起计时器_设计作品|最佳倒数计时器设计分析「附原型实例」
- 小程序获取sessionkey_微信小程序 获取session_key和openid的实例
- Opencv-python生成幻影坦克
- 计算机无法注册打印机,电脑打印机突然不运行了该怎么办?
- CMDB 腾讯云部分实现
- 质量体系-读大佬文章有感
- wireshark抓包常用命令
- python实现BMR计算器,日历计算,存钱挑战,分形树和五角星绘制等
- Elo顾客忠诚度 —— kaggle数据
热门文章
- SAP外向交货单中的批次拆分应用于免费货物的小问题
- 物料分类账的基本原理
- 在TABLE CONTROL 输入完一行记录,按回车的时候光标自动移动到下一行
- TYPE-POOLS
- 永洪科技斩获2019年度大数据分析创新产品和优秀方案2项殊荣
- 华中科技大学c语言作业答案,华中科技大学标准C语言程序设计及应用习题答案...
- centos7 如何安装部署k8s_五步教你如何使用k8s快速部署ES
- 计算机基础ABCDEF,计算机应用基础-在线作业abcdef(76页)-原创力文档
- 计算机无法显示移动硬盘,移动硬盘在我的电脑中不显示了 怎么处理?
- java方面的文献综述怎么写_文献综述应该怎么写?