Hystrix断路器-局部降级(在消费方设置)
(1)将服务提供方关于所有服务降级的设置全部去掉
(2)在服务消费方引入hsytrix依赖
一、服务消费方引入Hystrix依赖
<!-- hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
二、在启动类上开启服务熔断
@EnableCircuitBreaker //开启服务熔断,添加该注解才能进行服务降级
也可以用@SpringCloudApplication (这个注解包含了三个注解)
三、在controller类里编写降级逻辑
四、调用服务测试:
注解:
@HystrixCommand(fallbackMethod = "handeException", commandProperties = {
//设置峰值,超过 1.5 秒,就会调用降级逻辑方法
@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds", value = "5000")
})
测试完毕