spring cloud 的hystrix 熔断器 和feign 调用的使用
1, 添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2,yml 文件开启熔断
feign:
hystrix:
enabled: true
3,启动类上的注解
@EnableHystrix
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
4,feign 的接口
@FeignClient(name = "testInfo", fallback= RemoteHelloCallBack.class)
public interface RemoteHello {
@RequestMapping(value = "/hello/error", method = RequestMethod.GET)
public String getError();
@RequestMapping(value = "/hello/get", method = RequestMethod.GET)
public String getRemote();
}
5,hystrix 的使用
@Component
public class RemoteHelloCallBack implements RemoteHello {
@Override
public String getError() {
return "RemoteError is block";
}
@Override
public String getRemote() {
return "get Remote hello is block";
}
}
6, 控制层简单的调用
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "helle consul";
}
@Autowired
RemoteHello hello;
@RequestMapping("/getRemote")
public String getRemote() {
return hello.getRemote();
}
@RequestMapping("/geterror")
public String geterror() {
return hello.getError();
//return "this is error message..";
}
}
spring cloud 的hystrix 熔断器 和feign 调用的使用的更多相关文章
- spring cloud 声明式rest客户端feign调用远程http服务
在Spring Cloud Netflix栈中,各个微服务都是以HTTP接口的形式暴露自身服务的,因此在调用远程服务时就必须使用HTTP客户端.Feign就是Spring Cloud提供的一种声明式R ...
- Spring Cloud中Hystrix、Ribbon及Feign的熔断关系是什么?
导读 今天和大家聊一聊在Spring Cloud微服务框架实践中,比较核心但是又很容易把人搞得稀里糊涂的一个问题,那就是在Spring Cloud中Hystrix.Ribbon以及Feign它们三者之 ...
- Spring Cloud 服务端注册与客户端调用
Spring Cloud 服务端注册与客户端调用 上一篇中,我们已经把Spring Cloud的服务注册中心Eureka搭建起来了,这一章,我们讲解如何将服务注册到Eureka,以及客户端如何调用服务 ...
- Spring Cloud中,如何解决Feign/Ribbon第一次请求失败的问题?
Spring Cloud中,如何解决Feign/Ribbon第一次请求失败的问题? Spring Cloud中,Feign和Ribbon在整合了Hystrix后,可能会出现首次调用失败的问题,要如何解 ...
- Spring Cloud中Hystrix 线程隔离导致ThreadLocal数据丢失问题分析
最近spring boot项目中由于使用了spring cloud 的hystrix 导致了threadLocal中数据丢失,其实具体也没有使用hystrix,但是显示的把他打开了,导致了此问题. 导 ...
- spring cloud 系列第4篇 —— feign 声明式服务调用 (F版本)
源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.feign 简介 在上一个用例中,我们使用ribbon+restTem ...
- Spring Cloud中,如何解决Feign整合Hystrix第一次请求失败的问题
Spring Cloud中,Feign和Ribbon在整合了Hystrix后,可能会出现首次调用失败的问题,要如何解决该问题呢? 造成该问题的原因 Hystrix默认的超时时间是1秒,如果超过这个时间 ...
- Spring Cloud断路器Hystrix
在微服务架构中,存在着那么多的服务单元,若一个单元出现故障,就会因依赖关系形成故障蔓延,最终导致整个系统的瘫痪,这样的架构相较传统架构就更加的不稳定.为了解决这样的问题,因此产生了断路器模式. 什么是 ...
- Spring Cloud之Hystrix服务保护框架
服务保护利器 微服务高可用技术 大型复杂的分布式系统中,高可用相关的技术架构非常重要. 高可用架构非常重要的一个环节,就是如何将分布式系统中的各个服务打造成高可用的服务,从而足以应对分布式系统环境中的 ...
随机推荐
- nginx+waf防火墙
1.官网下载nginx源码包(nginx-1.20.0.tar.gz) 新建nginx安装目录mkdir -p /opt/nginx新增nginx运行用户useradd -s /sbin/nol ...
- 【剑指offer】51.构建乘积数组
51.构建乘积数组 知识点:数组: 题目描述 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0] * A[1] *... * A[i ...
- Jmeter任在运行,线程数上不去
问题 jmeter在运行,但是线程数上不去(本来模型设计了100个总线程,但运行时线程只能上到5,根据图上观察总共也只能运行5个线程) 之前更新了random csv插件 解决办法 查看jmeter. ...
- 你有没有乱用“leader”,担当是个好东西
PS:此文为个人认知,不足处请多多批评. 近期在一线leader(经理)身上发现了几个case,然后又回想起前几年自己做的一些傻事,可能都属于明面上leader不会说什么,但私下会有情绪的类型: Ca ...
- response 重定向
背景: controller层需要重定向到其他html界面时,需要用如下代码 // 设置302状态码 response.setStatus(302); // 设置location响应头 respons ...
- 第十六篇 -- SuperIO学习
一.SuperIO 这次主要研究SuperIO读取以及控制风扇转速的问题. 参考文章:https://huchanghui123.github.io/Linux/Linux-Superio-CPU-F ...
- Django报错:'Specifying a namespace in include() without providing an app_name '
环境:win10(64)+pycharm2018.3+python3.7 在网页项目中使用include()方法 项目目录中同时存在app/urls.py和proj/urls.py 在proj/url ...
- vue知识点---element el-date-picker 插件默认时间属性default-value怎么赋值?
参考网址: http://www.imooc.com/wenda/detail/509359 默认值,你放到 v-model里面就好. v-model="time" data(){ ...
- 关于在iar+j-link上的坑坑洼洼
引言 iar版本为8.32,j-link驱动版本为4.34,对应的是stm32 ARM cortex-m3 ,文末有本文的软件和工具,以及需要的文件的链接(免费) 第一坑:iar注册机不能注册iar9 ...
- 实战 | Hive 数据倾斜问题定位排查及解决
Hive 数据倾斜怎么发现,怎么定位,怎么解决 多数介绍数据倾斜的文章都是以大篇幅的理论为主,并没有给出具体的数据倾斜案例.当工作中遇到了倾斜问题,这些理论很难直接应用,导致我们面对倾斜时还是不知所措 ...