在8001服务提供方引入Hystrix依赖
org.springframework.cloud
spring-cloud-starter-netflix-hystrix
对 8001 的service进行配置(对容易超时的方法进行配置)
在启动类上开启服务熔断
@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker //开启服务熔断
public class HystrixPaymentApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixPaymentApplication.class,args);
}
}
启动8001服务测试
现在我们改动服务方里面的代码(模拟服务出现异常,而不是服务调用超时)
总结:
我们发现。只要是我们服务不可用了(调用超时、内部错误),都可以用降级来处理。