1. pom.xml中加入
1
2
3
4
|
<
dependency
>
<
groupId
>org.springframework.cloud</
groupId
>
<
artifactId
>spring-cloud-starter-hystrix</
artifactId
>
</
dependency
>
|
2. application.properties里面加入eureka配置
1
|
eureka.client.serviceUrl.defaultZone=http://host:port/eureka/
|
2. Application.java加入注解
@EnableCircuitBreaker,@EnableEurekaClient, @EnableDiscoveryClient
1
2
3
4
5
6
|
@EnableCircuitBreaker
@EnableDiscoveryClient
@EnableEurekaClient
public
class
SmartHomeAuthServiceMain {
}
|
3. 具体接口前加入回滚方法
1
2
3
4
5
6
7
8
9
10
11
|
@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"
}
|
回滚方法findOrderFallback参数和返回值和之前的一样
4. github配置文档
https://github.com/Netflix/Hystrix/wiki/Configuration
本文转自rongwei84n 51CTO博客,原文链接:http://blog.51cto.com/483181/1983571,如需转载请自行联系原作者