Hystrix使用

1、依赖包

<!-- 熔断相关依赖 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-hystrix</artifactId>
    <version>2.2.10.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-commons</artifactId>
    <version>2.2.9.RELEASE</version>
</dependency>

2、启动application启动类增加注解

@EnableHystrix
@EnableCircuitBreaker
 

3、被调用方法上增加注意

@HystrixCommand(commandProperties = {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")}, fallbackMethod = "getCouponFallback")
其他fallbackMethod为熔断时执行的方法
 

注意点:

1、熔断方法对应的类必须有对应的接口
2、增加@HystrixCommand需要是public方法(与第一点一致,即需要实现接口)
posted @ 2023-11-22 20:00  使用D  阅读(20)  评论(0编辑  收藏  举报