spring cloud: Hystrix(四):feign使用hystrix

@FeignClient支持回退的概念:fallback方法,这里有点类似于:@HystrixCommand(fallbackMethod = "notfindback")的fallbackMethod 方法。

fallback方法调用的是一个类.,feign也有:/health, /health.stream地址信息

http://192.168.1.4:7601/health

1.首先要在配置件开启hystrix配置

#feign.hystrix
feign.hystrix.enabled=true

  

或者

feign:
hystrix:
enabled: true

  

2.在FeignClient客户端文件添加fallback

@FeignClient(name="spring-boot-user", fallback=HystrixClientFallback.class)
public interface UserFeignClient { // 两个坑:1. @GetMapping不支持 2. @PathVariable得设置value
@RequestMapping(value="/simple/{id}", method=RequestMethod.GET)
public User findById(@PathVariable("id") Long id); }

  

3.HystrixClientFallback友好文件(当feignClient地址不通是,默认返回本类信息)

@Component
public class HystrixClientFallback implements UserFeignClient{ @Override
public User findById(Long id) {
// TODO Auto-generated method stub
User user = new User();
user.setId(0L);
return user;
} }

  

4.controller调用

@RestController
public class MovieController { @Autowired
private UserFeignClient userFeignClient; @GetMapping("/movie/{id}")
public User findById(@PathVariable("id") Long id) {
return this.userFeignClient.findById(id);
} }

  

spring cloud: Hystrix(四):feign类似于hystrix的断容器功能:fallback的更多相关文章

  1. Spring Cloud(Dalston.SR5)--Feign 与 Hystrix 断路器整合

    创建项目 要使 Feign 与 Hystrix 进行整合,我们需要增加 Feign 和 Hystrix 的依赖,修改 POM.xml 中增加以下依赖项如下: <?xmlversion=" ...

  2. <Spring Cloud>入门四 Feign

    1.Feign 之前使用的是Ribbon+RestTemplate调用,通过的是微服务的名字进行调用,实现负载均衡 但是为了满足接口编程,提供了Feign 2.实现 2.1引入坐标 在 ms-comm ...

  3. 0.9.0.RELEASE版本的spring cloud alibaba sentinel+feign降级处理实例

    既然用到了feign,那么主要是针对服务消费方的降级处理.我们基于0.9.0.RELEASE版本的spring cloud alibaba nacos+feign实例添油加醋,把sentinel功能加 ...

  4. Spring Cloud(四):服务容错保护 Hystrix【Finchley 版】

    Spring Cloud(四):服务容错保护 Hystrix[Finchley 版]  发表于 2018-04-15 |  更新于 2018-05-07 |  分布式系统中经常会出现某个基础服务不可用 ...

  5. Spring Cloud(五):Hystrix 监控面板【Finchley 版】

    Spring Cloud(五):Hystrix 监控面板[Finchley 版]  发表于 2018-04-16 |  更新于 2018-05-10 |  在上一篇 Hystrix 的介绍中,我们提到 ...

  6. Spring Cloud(六):Hystrix 监控数据聚合 Turbine【Finchley 版】

    Spring Cloud(六):Hystrix 监控数据聚合 Turbine[Finchley 版]  发表于 2018-04-17 |  更新于 2018-05-07 |  上一篇我们介绍了使用 H ...

  7. Spring Cloud(Dalston.SR5)--Feign 声明式REST客户端

    Spring Cloud 对 Feign 进行了封装,集成了 Ribbon 并结合 Eureka 可以实现客户端的负载均衡,Spring Cloud 实现的 Feign 客户端类名为 LoadBala ...

  8. Spring Cloud 入门 之 Feign 篇(三)

    原文地址:Spring Cloud 入门 之 Feign 篇(三) 博客地址:http://www.extlight.com 一.前言 在上一篇文章<Spring Cloud 入门 之 Ribb ...

  9. spring cloud: zuul(四): 正则表达式匹配其他微服务(给其他微服务加版本号)

    spring cloud: zuul(四): 正则表达式匹配其他微服务(给其他微服务加版本号) 比如我原来有,spring-boot-user微服务,后台进行迭代更新,另外其了一个微服务: sprin ...

随机推荐

  1. struts2 action中字符串转json对象出错 java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException

    commons-lang包有错,要么是引入错误,要么是没引入. 报不同错误,引入不同包. commons-beanutils-1.8.0.jar不加这个包 java.lang.NoClassDefFo ...

  2. 对应web的常用flutter应用

    例如,创建一个Text widget: new Text('Hello World', style: new TextStyle(fontSize: 32.0)) 创建一个 Image widget: ...

  3. 4698: Sdoi2008 Sandy的卡片

    前言 总之这个东西说起来很麻烦就是了, 思路 差分合并+后缀数组+二分(dddl) 类似于那个bzoj1031的复制子串和那个poj1743的差分 来看个例子 3 5 1 2 3 4 5 4 1 1 ...

  4. iis6-0 cve-2017-7269 批量验证脚本

    代码地址 import subprocess f = open('ips.txt', 'r') flines = f.readlines() vulnsrvs = 0 i = 1 for line i ...

  5. IDEA创建Maven Web项目

    简单介绍 本篇博客主要介绍使用IDEA如何创建Maven Web项目,具体是两个方面的内容:创建项目和配置tomcat服务器.前提是根据IDEA入门配置好了JDK及Maven. 创建项目 新建项目 填 ...

  6. com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction

    本文为博主原创: 以下为在程序运行过程中报的错误, org.springframework.dao.CannotAcquireLockException: ### Error updating dat ...

  7. dataTable表头未对其解决方法

    本文为博主原创,未经允许不得转载: 在tab页中使用dataTable时,默认显示的dataTable表头与数据显示正常,另一个的datatable则表头与数据未对其. 检查元素发现,datatabl ...

  8. 【NOIP 2015】Day2 T3 运输计划

    Problem Background 公元 \(2044\) 年,人类进入了宇宙纪元. Description 公元\(2044\) 年,人类进入了宇宙纪元. $L $国有 \(n\) 个星球,还有 ...

  9. 51nod 1349 最大值(单调栈)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1349 题意: 求区间内最大值大于等于k的区间个数. 思路: 利用求出对于 ...

  10. [从零开始搭网站六]为域名申请免费SSL证书(https),并为Tomcat配置https域名所用的多SSL证书

    点击下面连接查看从零开始搭网站全系列 从零开始搭网站 由于国内的网络环境比较恶劣,运营商流量劫持的情况比较严重,一般表现为别人打开你的网站的时候会弹一些莫名其妙的广告...更过分的会跳转至别的网站. ...