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
@EnableCircuitBreaker
3、被调用方法上增加注意
@HystrixCommand(commandProperties = {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")}, fallbackMethod = "getCouponFallback")
其他fallbackMethod为熔断时执行的方法
其他fallbackMethod为熔断时执行的方法
注意点:
1、熔断方法对应的类必须有对应的接口
2、增加@HystrixCommand需要是public方法(与第一点一致,即需要实现接口)