hystrix 全局熔断_跟我学Spring Cloud(Finchley版)14Feign使用Hystrix
Feign默认已经整合了Hystrix,本节详细探讨Feign使用Hystrix的具体细节。
服务降级
1 加配置,默认Feign是不启用Hystrix的,需要添加如下配置启用Hystrix,这样所有的Feign Client都会受到Hystrix保护!
feign:
hystrix:
enabled: true
2 提供Fallback:
@FeignClient(name = "microservice-provider-user", fallback = UserFeignClientFallback.class)
public interface UserFeignClient {
@GetMapping("/users/{id}")
User findById(@PathVariable("id") Long id);
}
@Component
class UserFeignClientFallback implements UserFeignClient {
@Override
public User findById(Long id) {
return new User(id, "默认用户", "默认用户", 0, new BigDecimal(1));
}
}
获得造成fallback的原因
@FeignClient(name = "microservice-provider-user", fallbackFactory = UserFeignClientFallbackFactory.class)
public interface UserFeignClient {
@GetMapping("/users/{id}")
User findById(@PathVariable("id") Long id);
}
@Component
@Slf4j
class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {
@Override
public UserFeignClient create(Throwable throwable) {
return new UserFeignClient() {
@Override
public User findById(Long id) {
log.error("进入回退逻辑", throwable);
return new User(id, "默认用户", "默认用户", 0, new BigDecimal(1));
}
};
}
}
Feign启用/禁用Hystrix
全局启用
feign.hystrix.enabled: true
全局禁用
feign.hystrix.enabled: false
或直接省略不写。
局部启用
利用Feign配置的自定义,为指定Feign Client指定如下配置类即可,Feign配置自定义详见:跟我学Spring Cloud(Finchley版)-10-Feign深入
public class FeignDisableHystrixConfiguration {
@Bean
@Scope("prototype")
public HystrixFeign.Builder feignBuilder() {
return HystrixFeign.builder();
}
}
局部禁用
public class FeignDisableHystrixConfiguration {
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
return Feign.builder();
}
}
配套代码
服务降级:
1 GitHub:https://github.com/eacdy/spring-cloud-study/tree/master/2018-Finchley/microservice-consumer-movie-feign-hystrix
2 Gitee:https://gitee.com/itmuch/spring-cloud-study/tree/master/2018-Finchley/microservice-consumer-movie-feign-hystrix
获得造成fallback的原因:
1 GitHub:https://github.com/eacdy/spring-cloud-study/tree/master/2018-Finchley/microservice-consumer-movie-feign-hystrix-fallback-factory
2 Gitee:https://gitee.com/itmuch/spring-cloud-study/tree/master/2018-Finchley/microservice-consumer-movie-feign-hystrix-fallback-factory
相关热文
实用技巧:Hystrix传播ThreadLocal对象(两种方案)
生产技巧:Feign如何控制Hystrix的启停、超时、熔断?
Hystrix停止开发,我们该何去何从?
Spring Cloud 源码学习之 Hystrix 熔断器
Spring Cloud Edgware新特性之二:如何配置Zuul的Hystrix线程池
跟我学Spring Cloud(Finchley版)-12-微服务容错三板斧
跟我学Spring Cloud(Finchley版)-13-通用方式使用Hystrix
您的关注是对我最大的支持!
hystrix 全局熔断_跟我学Spring Cloud(Finchley版)14Feign使用Hystrix相关推荐
- Spring Cloud Finchley版中Consul多实例注册的问题处理
由于Spring Cloud对Etcd的支持一直没能从孵化器中出来,所以目前来说大多用户还在使用Eureka和Consul,之前又因为Eureka 2.0不在开源的消息,外加一些博眼球的标题党媒体使得 ...
- 一起来学Spring Cloud | 第五章:熔断器 ( Hystrix)
在微服务项目中,一个系统可以分割成很多个不同的服务模块,不同模块之间我们通常需要进行相互调用.springcloud中可以使用RestTemplate+Ribbon和Feign来调用(工作中基本都是使 ...
- 告诉老默我想学Spring Cloud了(新手篇):从0到1搭建Spring Cloud项目(实际项目开发的浓缩精华版)
告诉老默我想学Spring Cloud了(新手篇):从0到1搭建Spring Cloud项目 一.前言 二.如何选择版本 2.1 SpringCloud 和 Spring Boot 版本选型 2.1. ...
- 跟我学Spring Cloud(Finchley版)-10-Feign深入
上一节( 跟我学Spring Cloud(Finchley版)-09-Feign )讲了Feign的入门姿势并深入对比了RestTemplate,本节来深入探讨Feign的高级特性.总的来说,Feig ...
- 跟我学Spring Cloud(Finchley版)-07-Ribbon入门
经过前文讲述,我们已经实现了服务发现.本节来解决 跟我学Spring Cloud(Finchley版)-02-构建分布式应用 提到的如下问题: 负载均衡如何考虑?难道得在电影微服务和用户微服务之间加个 ...
- 跟我学Spring Cloud(Finchley版)-04-服务注册与服务发现-原理剖析
为什么80%的码农都做不了架构师?>>> 第2节( 跟我学Spring Cloud(Finchley版)-02-构建分布式应用 )说过: 地址硬编码问题--电影微服务中将用户微 ...
- dubbo web工程示例_带有Dubbo的Spring Cloud Alibaba
在优锐课的学习分享中,我们可以看到关于如何在阿里巴巴的Spring Cloud实现中使用这个流行的RPC框架. 1.Spring Cloud Alibaba Spring Cloud Alibaba是 ...
- Spring Cloud Finchley OpenFeign的重试配置相关的坑
如题,本文基于Spring Cloud Finchley.SR2 OpenFeign的重试 OpenFeign配置重试后,逻辑分析 对比Daltson和Finchley的基本组件,发现Ribbon还有 ...
- Spring Cloud(十一):Hystrix服务熔断-工作流程
1. Hystrix服务熔断 1.1 断路器 类似保险丝 1.2 熔断是什么 熔断机制是应对雪崩效应的一种微服务链路保护机制.当扇出链路的某个微服务出错不可用或者响应时间太长时,会进行服务的降级,进而 ...
最新文章
- Android EditView 软键盘把布局顶上去的处理方法
- docker(4)docker的网络,自定义网桥
- FoundationDB Record Layer 宣布开源,提供关系数据库功能
- 模糊测试工具Simple Fuzzer
- (*长期更新)软考网络工程师学习笔记——Section 4 物理层的其它知识
- VS2010下Boost1.55.0配置
- mysql查询语句不返回_PHP-CI MySQL查询联接表,并且where语句不返回所...
- 设计模式的理解的总结
- 一键自动生成数据库文档,炫!(告别CV大法)
- 解决openfire在使用MySQL数据库后的中文乱码问题(转)
- 蓝牙鼠标windows linux,在Deepin和Windows 10双系统中蓝牙4.0鼠标共享使用的方法
- php提升并发,php高并发处理
- 万能的5款工具推进活动策划方案
- 初级算法题->有效的数独--弄清哈希表的本质
- 写一段wavefront_reader的代码
- 开源电子原型平台 Arduino
- 使用4G模块实现IOT_Python库中,如何使用jieba模块来实现古典名著《西游记》的分词...
- 西北工业大学noj数据结构表达式括号匹配(严3.19)
- JUC笔记(三)多线程的核心
- linux ps -ef和ps -aux,关于Linux中ps -aux的深入理解
热门文章
- 3行代码实现ftp 上传、下载、删除操作集合
- SpringBoot 整合ActiveMQ_企业实战
- mysql中的锁的指令_mysql中的锁
- java内部类实现方式_Java内部类详解
- C语言 文件读写 fputs 函数 - C语言零基础入门教程
- C语言 va_start / va_end / va_arg 自定义 printf 函数 - C语言零基础入门教程
- weex android 性能,跨越适配性能那道坎,企鹅电竞Android weex优化
- C语言extern与static修饰变量
- 水面反光如何拍摄_拍摄水面反射的创意
- python自动化测试脚本可以测php吗_python unittest实现api自动化测试_python