实战前需了解:https://blog.csdn.net/wanzijy/article/details/125041622
Hystrix熔断器整合 - 搭建项目:https://blog.csdn.net/wanzijy/article/details/125496651
Hystrix熔断器整合 - 请求缓存:https://blog.csdn.net/wanzijy/article/details/125512072
Hystrix熔断器整合 - 请求合并:https://blog.csdn.net/wanzijy/article/details/125579664
Hystrix熔断器整合 - 服务隔离之线程池隔离:https://blog.csdn.net/wanzijy/article/details/125630353
Hystrix熔断器整合 - 服务隔离之信号量隔离:https://blog.csdn.net/wanzijy/article/details/125826690
Hystrix熔断器整合 - 服务熔断和服务降级:https://blog.csdn.net/wanzijy/article/details/125826853
Hystrix熔断器整合 - Feign实现服务容错:https://blog.csdn.net/wanzijy/article/details/125985304
Hystrix熔断器整合 - 可视化界面三部曲:https://blog.csdn.net/wanzijy/article/details/126005452
1. Autuator
1.1 在 order-service-rest 中导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
1.2 配置文件
# 度量指标监控与健康检查
management:
endpoints:
web:
exposure:
include: hystrix.stream
1.3 测试
注意端口号要换成自己的
访问:http://localhost:9090/actuator 可以看到如下:
再访问 http://localhost:9090/actuator/hystrix.stream 会看到一直的在 ping
不过可以看到,由于是 json 数据,不好观察,但还是可以看到项目中的一些情况
2. 监控中心
将上述 Autuator 显示的 json 数据可视化
2.1 在 order-service-rest 中导入依赖并开启数据监控
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
在启动类上加上 @EnableHystrixDashboard
2.2 测试
注意下面涉及的端口号要换成自己的
访问 http://localhost:9090/hystrix
在输入框中输入 Autuator 暴露的地址 http://localhost:9090/actuator/hystrix.stream
然后点击按钮,此时看控制台是否出现以下打印,有则连接成功
再回到可视化界面,一开始是处于 loading 状态,因为还没有访问接口获取数据
当访问接口后,如下:
上述的数据,是可以实时进行刷新的,意思是每当你访问一下请求,都会发生变化
2.3 图解
2.4 思考
首先先自行去 order-service-feign 搭建上面的 Autuator 和 监控中心
然后想:因为微服务会有很多的模块,如果每一个模块都要这样去重复上述的操作,会很麻烦。所以要将监控中心聚合起来
3. Turbine 聚合监控中心
搭建一个新的模块 hystrix-turbine
3.1 导入依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
</dependencies>
3.2 配置文件
server:
port: 8181
spring:
application:
name: hystrix-turbine
eureka:
instance:
prefer-ip-address: true # 是否使用 ip 地址注册
instance-id: ${spring.cloud.client.ip-address}:${server.port} # ip:port
client:
service-url: # 设置服务注册中心地址
defaultZone: http://eureka01:8761/eureka/,http://eureka02:8762/eureka/
register-with-eureka: true
fetch-registry: true
turbine:
app-config: order-service-rest, order-service-feign # 要监控的服务列表,多个用逗号分割
cluster-name-expression: "'default'" # 指定集群名称
3.3 启动类
@SpringBootApplication
@EnableHystrix
@EnableHystrixDashboard
@EnableTurbine
public class HystrixTurbineApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixTurbineApplication.class, args);
}
}
3.4 启动类
访问 http://localhost:8181/hystrix 可以看到和监控中心一样的画面
可以先访问 http://localhost:8181/turbine.stream 看看 ping 的 json 数据
然后在输入框中输入 http://localhost:8181/turbine.stream 可以看到所有的监控都在这里了