# springcloud-chapter05-1 **Repository Path**: fybtime/springcloud-chapter05-01 ## Basic Information - **Project Name**: springcloud-chapter05-1 - **Description**: 第五章服务容错保护库 Hystrix - **Primary Language**: Java - **License**: Not specified - **Default Branch**: c1 - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 203 - **Created**: 2023-04-10 - **Last Updated**: 2023-04-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # springcloud-chapter05-01 #### 介绍 第五章服务容错保护库 Hystrix 基于Feign中使用 教材P70 Feign组件包含了Hystrix 熔断功能,但需要配置启用 需要**重点掌握** #### 软件架构 软件架构说明 小组成员 09冯烨彬 55杨俊 23李梓彬 13黄大锋 #### 安装教程 客户端配置文件截图: ![输入图片说明](doc/1.png) ![输入图片说明](doc/4.png) ![输入图片说明](doc/5.png) ![输入图片说明](doc/6.png) 1. 运行 Eureka Server 2. 运行 hello-provider 3. 运行 eureka-hystrix-client,发请求测试效果 4. 停止 hello-provider 5. 发请求测试效果 #### 效果 运行在服务器A46 ![输入图片说明](doc/7.png) ![输入图片说明](doc/2.png) ![输入图片说明](doc/3.png) 停止 hello-provider 后的效果 ![输入图片说明](doc/10.png) ![输入图片说明](doc/8.png) ![输入图片说明](doc/9.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/2-1.png) ![](./doc/2-2.png)