feign本身是支持Hystrix的,所以不需要引入其他依赖:

我们可以看看feign这个项目的依赖,就是引入这个依赖的pom.xml

要想看这个很简单,点击那个依赖进去就可以了

点进去就可以看到

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign</artifactId>
<version>2.1..RELEASE</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<name>Spring Cloud Starter OpenFeign</name>
<description>Spring Cloud Starter OpenFeign</description>
<url>https://projects.spring.io/spring-cloud</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>https://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-slf4j</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-hystrix</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-java8</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-archaius</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>

是本身就支持的,所以直接使用就可以了:

使用很简单:

在yml文件中开启:

feign:
hystrix:
enabled: true

看之前写的调用接口:

package com.cxy.service;

import com.cxy.dataObject.PersonDo;
import com.cxy.service.impl.PersonServiceImpl;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; @FeignClient(value = "cxy-person-service",fallback=PersonServiceImpl.class)
public interface IPersonService {
@RequestMapping("/person/{id}")
PersonDo getPersonDoById(@PathVariable("id")Integer id);
}

那个如果服务出现问题了就进入实现类的方法中

然后填写一个实体类就可以了:

package com.cxy.service.impl;

import com.cxy.dataObject.PersonDo;
import com.cxy.service.IPersonService;
import org.springframework.stereotype.Component; /***
* @ClassName: PersonServiceImpl
* @Description:
* @Auther: 陈绪友
* @Date: 2019/1/2821:09
* @version : V1.0
*/
@Component
public class PersonServiceImpl implements IPersonService {
@Override
public PersonDo getPersonDoById(Integer id) {
return new PersonDo(,"",,"");
}
}

不启动person服务看结果:

是在实现类中的数据,代表生效了

springcloud系列八 整合Hystrix的更多相关文章

  1. springcloud系列九 整合Hystrix Dashboard

    Hystrix Dashboard是Hystrix的仪表盘组件,主要用来实时监控Hystrix的各项指标信息,通过界面反馈的信息可以快速发现系统中存在的问题. 整合快速体验: pom.xml(这个是F ...

  2. springcloud系列10 整合Hystrix遇到的坑:

    首先配置类: @Bean public ServletRegistrationBean getServlet(){ HystrixMetricsStreamServlet streamServlet ...

  3. SpringCloud系列七:Hystrix 熔断机制(Hystrix基本配置、服务降级、HystrixDashboard服务监控、Turbine聚合监控)

    1.概念:Hystrix 熔断机制 2.具体内容 所谓的熔断机制和日常生活中见到电路保险丝是非常相似的,当出现了问题之后,保险丝会自动烧断,以保护我们的电器, 那么如果换到了程序之中呢? 当现在服务的 ...

  4. SpringCloud系列十七:Hystrix的监控

    1. 回顾 上文讲解了使用Hystrix为Feign添加回退,并通过Fallback Factory检查回退原因以及如何为Feign客户端禁用Hystrix. 2. Hystrix的监控 除实现容错外 ...

  5. springcloud系列七 整合slueth,zipkin 分布式链路调用系统:

    首先在代码里面引入依赖: <dependency> <groupId>org.springframework.cloud</groupId> <artifac ...

  6. springcloud系列六 整合security

    一 Eureka注册中心认证: Eureka自带了一个管理界面,如果不加密,所有人都可以进行访问这个地址,这样安全问题就来了,所以需要对其进行加密认证: 那么该如何进行整合呢: 1 在注册中心模块添加 ...

  7. SpringCloud系列八:Zuul 路由访问(Zuul 的基本使用、Zuul 路由功能、zuul 过滤访问、Zuul 服务降级)

    1.概念:Zuul 路由访问 2.具体内容 在现在为止所有的微服务都是通过 Eureka 找到的,但是在很多的开发之中为了规范微服务的使用,提供有一个路由的处理控制组件:Zuul,也就是说 Zuul ...

  8. SpringCloud系列八:自定义Ribbon配置

    1. 回顾 上文使用Ribbon实现了客户端侧的负载均衡.但是很多场景下,我们可能需要自定义Ribbon的配置,比如修改Ribbon的负载均衡规则. Spring Cloud允许使用Java代码或属性 ...

  9. springcloud系列11 整合微服务网关zuul

    这个模块是一个独立的模块所以需要建立一个模块, 首先引入: 依赖pom.xml <?xml version="1.0" encoding="UTF-8"? ...

随机推荐

  1. CreateMutex实现只能打开一个客户端

    #include "stdafx.h" #include <Windows.h> #include <iostream> using namespace s ...

  2. 类型:Oracle;问题:oracle 时间加减;结果:ORACLE 日期加减操作

    ORACLE 日期加减操作 无论是DATE还是timestamp都可以进行加减操作. 可以对当前日期加年.月.日.时.分.秒,操作不同的时间类型,有三种方法: 1 使用内置函数numtodsinter ...

  3. adb eclipse 截屏

    DDMS  左侧  选中设备 右上角有一个相机样式的按钮"screen capture"

  4. nginx负载均衡, 配置地址带端口

    nginx.conf  配置如下: upstream wlcf.dev.api { server 127.0.0.1:8833; server 127.0.0.2:8833; } server { l ...

  5. iOS 聊天界面

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  6. hibernate第三天 一对多 , 多对多

    1.1. 阐述你对inverse的理解 答: 1.inverse的默认值是false,代表不放弃外键维护权,配置值为true,代表放弃了外键的维护权. 2.双方维护外键会多产生update语句,造成浪 ...

  7. js实现上传单个文件

    js上传文件:js 上传单个文件(任意大小) 疯狂代码 http://www.CrazyCoder.cn/ :http:/www.CrazyCoder.cn/Javascript/Article832 ...

  8. SDUT 2129 树结构练习——判断给定森林中有多少棵树

    树结构练习——判断给定森林中有多少棵树 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description  众 ...

  9. Umbraco 中获取一个media item的文件路径 file path

    我们要使用UmbracoHelper, 这里就需要用到我们在之前的blog里面写的UmbracoContext 参看这个blog     https://www.cnblogs.com/wphl-27 ...

  10. win7搭建TensorFlow环境

    官网安装指南地址:https://www.tensorflow.org/install/pip 安装过程碰到的问题: 1.创建虚拟环境 virtualenv --system-site-package ...