2017-02-20 65 views
0

当我研究与hystrix春假云虚假,有一个问题,即 如果我使用LOGGER.info(“**** {}”,cause.getMessage()),后备不起作用,UserFeignClient#findById(长)超时和回退失败。但是,如果我删除cause.getMessage(),回退是可以的。为什么?春天云hystrix fallbackfactory

public class UserFeignFallBackFactory implements FallbackFactory<UserFeignClient> { 

    private static final Logger LOGGER = LoggerFactory.getLogger(UserFeignFallBackFactory.class); 

    @Override 
    public UserFeignClient create(Throwable cause) { 
     LOGGER.info("call UserFeignClient error, error msg is : {}"); 
     return new UserFeignClientEx() { 
      @Override 
      public User findById(@PathVariable("id") Long id) { 
       return new User(-1L, null, null, (short) 20); 
      } 
     }; 
    } 
} 

enter image description here

回答

0

你可以尝试这样的

public class UserFeignFallBackFactory implements FallbackFactory<UserFeignClient> { 

private static final Logger LOGGER = LoggerFactory.getLogger(UserFeignFallBackFactory.class); 

@Override 
public UserFeignClient create(Throwable cause) { 

    return new UserFeignClientEx() { 
     @Override 
     public User findById(@PathVariable("id") Long id) { 
      LOGGER.info("call UserFeignClient error, error msg is : {}"); 
      return new User(-1L, null, null, (short) 20); 
     } 
    }; 
} 
}