[英]spring cloud hystrix fallbackfactory
when i study spring cloud feign with hystrix, have a problem, that if i use LOGGER.info("**** {}", cause.getMessage()), the fallback is not work, UserFeignClient#findById(Long) timed-out and fallback failed. 当我用hystrix研究Spring cloud伪装时,遇到一个问题,如果我使用LOGGER.info(“ **** {}”,cause.getMessage()),后备功能将不起作用,UserFeignClient#findById(Long)会计时退出和后备失败。 But if i remove cause.getMessage(), fallback is ok. 但是,如果我删除cause.getMessage(),回退就可以了。 Why? 为什么?
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);
}
};
}
}
you can try like this 你可以这样尝试
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);
}
};
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.