hystrix 熔断机制,用于服务间互相调用的熔断,结合feign使用
配置方式
1 2 3 4
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency>
|
1 2 3 4
| feign: hystrix: enabled: true
|
1 2 3 4 5 6 7 8 9
| @Component public class HystrixReturn implements MyFeign {
@Override public String provide() { System.out.println("我熔断了"); return "我熔断了"; } }
|
继承与feign的接口,即会对每一个feign做一个降级熔断返回信息配置
1 2 3 4 5 6 7 8 9
| @FeignClient(value = "feign-provider",fallback = HystrixReturn.class) @Component public interface MyFeign {
@GetMapping("/provide/ces") String provide(); }
|
注解中添加降级的熔断返回信息配置类