如何解决如何让 HystrixCommand 适用于服务类中的所有函数
在一个服务类中,有四个函数,这些函数都使用RestTemplate来远程调用第三个服务器。
以下是示例:
@Service
public class PaymentService
{
@HystrixCommand(fallbackMethod = "paymentCircuitBreaker_fallback",commandProperties = {
@HystrixProperty(name = "circuitBreaker.enabled",value = "true"),@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold",value = "10"),@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds",value = "10000"),@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage",value = "60"),})
public String function1(@PathVariable("id") Integer id)
{
// some restTemplate action
}
@HystrixCommand(fallbackMethod = "paymentCircuitBreaker_fallback",})
public String function2(@PathVariable("id") Integer id)
{
// some restTemplate action
}
@HystrixCommand(fallbackMethod = "paymentCircuitBreaker_fallback",})
public String function3(@PathVariable("id") Integer id)
{
// some restTemplate action
}
public String paymentCircuitBreaker_fallback(@PathVariable("id") Integer id)
{
return "Server [PaymentService][paymentCircuitBreaker_fallback] id=" + id;
}
}
但是三个函数都把@HystrixCommand 头和属性都做成了一样不好,那么有没有办法只写一次?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。