# eureka-Hystrix+Fegin **Repository Path**: AnywayUDA/anyway ## Basic Information - **Project Name**: eureka-Hystrix+Fegin - **Description**: Feign+Hystrix综合实验 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2023-04-18 - **Last Updated**: 2023-06-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # springcloud-chapter05-01 组员(4人): 黄海滨 20200407430314 林泳亮 20200407430331 周南养 20200407430365 曾宇晨 20200407430303 #### 介绍 第五章服务容错保护库 Hystrix 基于Feign中使用 教材P70 Feign组件包含了Hystrix 熔断功能,但需要配置启用 需要**重点掌握** #### 软件架构 软件架构说明 #### 安装教程 Feign客户端配置 ```yaml server: port: 8764 spring: application: name: eureka-hystrix-client eureka: client: service-url: defaultZone: http://localhost:7000/eureka/ instance: hostname: localhost feign: hystrix: enabled: true ``` ![](./doc/12.png) ![](./doc/13.png) 1. 运行 Eureka Server ![](./doc/10.png) 2. 运行 hello-provider ![](./doc/11.png) 3. 运行 eureka-hystrix-client,发请求测试效果 ![](./doc/6.png) ![](./doc/7.png) 4. 停止 hello-provider ![](./doc/9.png) ![](./doc/8.png) 5. 发请求测试效果 #### 效果 ![](./doc/3.png) ![](./doc/16.png) ![](./doc/17.png) 停止 hello-provider 后的效果 ![](./doc/4.png) ![](./doc/18.png) ![](./doc/19.png) ### Hystrix Dashboard 监控 > eureka-hystrix-client 下 pom.xml 添加 ```xml org.springframework.cloud spring-cloud-starter-netflix-hystrix-dashboard org.springframework.boot spring-boot-starter-actuator ``` > 主程序添加注解 EurekaHystrixClientApplication ```java @SpringBootApplication @EnableFeignClients @EnableEurekaClient @EnableHystrixDashboard public class EurekaHystrixClientApplication { public static void main(String[] args) { SpringApplication.run(EurekaHystrixClientApplication.class, args); } } ``` >添加配置类 HystrixDashboardConfiguration ```java @Configuration public class HystrixDashboardConfiguration { @Bean public ServletRegistrationBean getServlet() { HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; } } ``` #### 监控效果图 ![](./doc/14.png) ![](./doc/15.png)