j2e*_*nue 2 java netflix hystrix
我正在使用@HystrixCommand在 Java 服务器中创建回退。
这是我拥有的一种方法,但我遇到的问题是我想知道我是否允许退回?
@HystrixCommand(fallbackMethod = "doFallback", commandKey = "doFallbackCommand")
   public Response getGraphPoints(String Id, String position) {
//do some work ... finally create a response
       return a_response;
   }
   public Response doFallback(String Id, String position) {
     //can i do this in hystrix command ? or do i really have to return a Response here?no other method will catch this throw for now
       throw new ServiceUnavailableException("points could not be found");
   }
我问的原因是当我运行这个时,我收到以下错误:
ERROR [HystrixTimer-1] [com.netflix.hystrix.contrib.javanica.command.GenericCommand] [myserver] failed to processed fallback is the method: 'doFallback'. 
小智 6
我遇到了同样的问题,现在我了解了 hystrix 的工作原理。Hystrix 不需要您设置一种回退方法。除非您想返回默认数据或为这种情况添加业务逻辑,否则没有必要。如果你抛出一个异常,你会“混淆”hystrix,所以它会抛出一个 HystrixRuntimeException。
我希望它有帮助。