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 调用的使用的更多相关文章

  1. spring cloud 声明式rest客户端feign调用远程http服务

    在Spring Cloud Netflix栈中,各个微服务都是以HTTP接口的形式暴露自身服务的,因此在调用远程服务时就必须使用HTTP客户端.Feign就是Spring Cloud提供的一种声明式R ...

  2. Spring Cloud中Hystrix、Ribbon及Feign的熔断关系是什么?

    导读 今天和大家聊一聊在Spring Cloud微服务框架实践中,比较核心但是又很容易把人搞得稀里糊涂的一个问题,那就是在Spring Cloud中Hystrix.Ribbon以及Feign它们三者之 ...

  3. Spring Cloud 服务端注册与客户端调用

    Spring Cloud 服务端注册与客户端调用 上一篇中,我们已经把Spring Cloud的服务注册中心Eureka搭建起来了,这一章,我们讲解如何将服务注册到Eureka,以及客户端如何调用服务 ...

  4. Spring Cloud中,如何解决Feign/Ribbon第一次请求失败的问题?

    Spring Cloud中,如何解决Feign/Ribbon第一次请求失败的问题? Spring Cloud中,Feign和Ribbon在整合了Hystrix后,可能会出现首次调用失败的问题,要如何解 ...

  5. Spring Cloud中Hystrix 线程隔离导致ThreadLocal数据丢失问题分析

    最近spring boot项目中由于使用了spring cloud 的hystrix 导致了threadLocal中数据丢失,其实具体也没有使用hystrix,但是显示的把他打开了,导致了此问题. 导 ...

  6. spring cloud 系列第4篇 —— feign 声明式服务调用 (F版本)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.feign 简介 在上一个用例中,我们使用ribbon+restTem ...

  7. Spring Cloud中,如何解决Feign整合Hystrix第一次请求失败的问题

    Spring Cloud中,Feign和Ribbon在整合了Hystrix后,可能会出现首次调用失败的问题,要如何解决该问题呢? 造成该问题的原因 Hystrix默认的超时时间是1秒,如果超过这个时间 ...

  8. Spring Cloud断路器Hystrix

    在微服务架构中,存在着那么多的服务单元,若一个单元出现故障,就会因依赖关系形成故障蔓延,最终导致整个系统的瘫痪,这样的架构相较传统架构就更加的不稳定.为了解决这样的问题,因此产生了断路器模式. 什么是 ...

  9. Spring Cloud之Hystrix服务保护框架

    服务保护利器 微服务高可用技术 大型复杂的分布式系统中,高可用相关的技术架构非常重要. 高可用架构非常重要的一个环节,就是如何将分布式系统中的各个服务打造成高可用的服务,从而足以应对分布式系统环境中的 ...

随机推荐

  1. WSL2:在Windows系统中开发Linux程序的又一神器

    作 者:道哥,10+年的嵌入式开发老兵. 公众号:[IOT物联网小镇],专注于:C/C++.Linux操作系统.应用程序设计.物联网.单片机和嵌入式开发等领域. 公众号回复[书籍],获取 Linux. ...

  2. python 动态指定header获取网页源代码的函数

    import random import requests def get_htmla(url): aui=0 while aui==0: try: header={'User-Agent':'Moz ...

  3. VisualEffectGraph基础操作 --创建VEG项目步骤讲解

    一:建立VEG项目步骤 首先打开Unity Hub,  使用unity2020.1 新建项目(本技术博客,默认使用unity2020.1 版本演示),选择HDRP 高清渲染管线,确定项目目录与名称. ...

  4. HDFS学习总结之安装

    HDFS linux安装总结(基于hadoop-2.6.0-cdh5.7.0 伪分部安装) 1.jdk安装 1) 直接下载jdk包放到安装目录即可(jdk-8u131-linux-x64.tar.gz ...

  5. deepin解压乱码

    使用unzip命令解压:unzip -O GBK xxxx.zip -d xxx

  6. MySQL问题定位-性能优化之我见

    前言 首先任何一个数据库不是独立存在的,也不是凭空想象决定出来的. 数据库的架构离不开应用的场景.所以,为了解决某些深入的问题,首先你得掌握数据库的原理与架构.原理掌握得越深入,越能帮助你定位复杂与隐 ...

  7. python里面的垃圾回收机制

    文章链接:https://www.jianshu.com/p/1e375fb40506 Garbage collection(GC) 现在的高级语言如java,c#等,都采用了垃圾收集机制,而不再是c ...

  8. JBoss 5.x/6.x 反序列化漏洞(CVE-2017-12149)

    检测

  9. 大数据学习(15)—— B+树和LSM

    这一节介绍数据库存储引擎常用的两种数据结构.作为关系型数据库的代表,MySql的InnoDB使用B+树来存储索引.作为NoSQL的代表,HBase使用的LSM树,我们来看看两者有什么区别. B+树 B ...

  10. Android技术分享| 实现视频连麦直播

    视频连麦产品端核心步骤分析 游客申请连麦/取消申请 主播同意/拒绝申请 音视频发布取消 支持很多观众观看 支持多人连麦 低延时 IM 弹幕 视频连麦技术端调研 emmm,大致可以分为视频采集.编码,传 ...