# springcloud-chapter05-02
**Repository Path**: Vakishim/springcloud-chapter05-02
## Basic Information
- **Project Name**: springcloud-chapter05-02
- **Description**: 第5章 容错服务 教材P70,P74
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 61
- **Created**: 2024-10-25
- **Last Updated**: 2024-10-25
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# springcloud-chapter05-01
#### 介绍
第五章服务容错保护库 Hystrix
基于Feign中使用
教材P70 Feign组件包含了Hystrix 熔断功能,但需要配置启用
需要**重点掌握**
#### 软件架构
基于Feign实现类图

#### 安装教程
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
```
1. 运行 Eureka Server
2. 运行 hello-provider
3. 运行 eureka-hystrix-client,发请求测试效果
4. 停止 hello-provider
5. 发请求测试效果
#### 效果

停止 hello-provider 后的效果

### 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;
}
}
```
#### 监控效果图

