45. Hystrix熔斷器加入
阿新 • • 發佈:2017-11-20
熔斷器
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
本文出自 “www.bogo.com” 博客,請務必保留此出處http://483181.blog.51cto.com/473181/1983571
45. Hystrix熔斷器加入