1. pom.xml中加入
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency>
2. Application.java加入注解
@EnableCircuitBreaker,@EnableEurekaClient, @EnableDiscoveryClient
@EnableCircuitBreaker @EnableDiscoveryClient @EnableEurekaClient public class SmartHomeAuthServiceMain { }
3. 具体接口前加入回滚方法
@HystrixCommand(fallbackMethod = "findOrderFallback", commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000") }) public String authPublishMessage(@RequestBody InnerAuthPublishMessageModel requestParas) { } public String findOrderFallback(InnerAuthPublishMessageModel requestParas) { return "failed" }
4. github配置文档
https://github.com/Netflix/Hystrix/wiki/Configuration
时间: 2024-10-21 07:40:13