问题描述
在一个服务类中,有四个函数,这些函数都使用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 (将#修改为@)