我是靠谱客的博主 温暖黑米,这篇文章主要介绍Spring Cloud Hystrix降级处理超时时间设置execution.isolation.thread.timeoutInMilliseconds,现在分享给大家,希望可以做个参考。
默认情况下调用接口能够触发Hystrix服务降级处理的超时时间是1000ms,我们可以通过HystrixCommandProperties类的源码查找到,如下图:

点击属性default_executionTimeoutInMilliseconds进去就是我们需要的配置execution.isolation.thread.timeoutInMilliseconds

属性execution.isolation.thread.timeoutInMilliseconds可以通过代码的方式配置生效:
package com.eureka.client.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
@Service
public class TestService {
@Autowired
private RestTemplate restTemplate;
@HystrixCommand(fallbackMethod = "helloFallback", commandProperties= {@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds", value="1200")})
public String helloService() {
String result = restTemplate.getForObject("http://EUREKA-SERVER/add", String.class);
System.out.println(result);
return result;
}
public String helloFallback() {
return "timeout";
}
}
当然网上我看也有很多说是可以通过application.properties配置文件配置的,但是我试验了不可以的,如果哪位知道原因请多多交流。
最后
以上就是温暖黑米最近收集整理的关于Spring Cloud Hystrix降级处理超时时间设置execution.isolation.thread.timeoutInMilliseconds的全部内容,更多相关Spring内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复