服务内熔断
服务内添加调用失败时的方法
public String helloError(){
return “request Error”;
}
并且在对应的接口中用@HystrixCommand注解传入
@HystrixCommand(fallbackMethod = “helloError”)
public String helloService() {
return restTemplate.getForEntity(“http://user/getUser”,String.class).getBody();
}
feign远程调用熔断
在对应熔断的接口中添加
@FeignClient(value = “message-api”,fallback = MessageApiFailBack.class)
MessageApiFailBack为熔断时调用的方法
统一修改
- 配置文档修改
开启hystrix熔断机制 feign.hystrix.enabled=true - 设置成永久不超时
hystrix.command.default.execution.timeout.enabled=false - 开启hystrix请求超时机制
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000