SpringCloud——hystrix熔断器

Hystrix能做什么?

服务熔断、服务降级、服务限流、接近实时的监控...

参考:https://github.com/Netflix/Hystrix/wiki/How-To-Use

一旦调用服务方法失败并抛出了错误信息后,会自动调用 @HystrixCommand 标注好的 fallbackMethod 调用类中的指定方法。

dashboard监控窗口:

7色,1圈,1线

配置

被监控端需要引入以下依赖

<!-- actuator监控信息完善 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--  hystrix -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>

加以下注解:
@SpringBootApplication
@EnableDiscoveryClient //服务发现
@EnableCircuitBreaker

监控端需要引入以下依赖

<!-- hystrix和 hystrix-dashboard相关-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>

加以下注解:
@SpringBootApplication
@EnableHystrixDashboard

猜你喜欢

转载自www.cnblogs.com/tangjian07/p/12167025.html