server: port: 8081 spring: application: name: spring-hy-sale feign: hystrix: enabled: true hystrix: command: HelloClient#toHello(): execution: isolation: thread: timeoutInMilliseconds: 500 circuitBreaker: requestVolumeThreshold: 3 eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/
@FeignClient(name = "spring-hy-member", fallback = HelloClientFallback.class) public interface HelloClient { @RequestMapping(method = RequestMethod.GET, value = "/hello") public String hello(); @RequestMapping(method = RequestMethod.GET, value = "/toHello") public String toHello(); }
@Component public class HelloClientFallback implements HelloClient { public String hello() { return "fallback hello"; } public String toHello() { return "fallback timeout hello"; } }
@RestController public class FeignController { @Autowired private HelloClient helloClient; @RequestMapping(method = RequestMethod.GET, value = "/hello") public String hello() { return helloClient.hello(); } @RequestMapping(method = RequestMethod.GET, value = "/toHello") public String toHello() throws InterruptedException { Thread.sleep(500); String result = helloClient.toHello(); HystrixCircuitBreaker breaker = HystrixCircuitBreaker.Factory .getInstance(HystrixCommandKey.Factory .asKey("HelloClient#toHello()")); System.out.println("断路器状态:" + breaker.isOpen()); return result; } }
原文地址:https://www.cnblogs.com/zfzf1/p/8552512.html
时间: 2024-11-05 20:46:49