如果将execution.isolation.thread.timeoutInMilliseconds
设置为20000
,并关闭测试远程服务:http://localhost:8081/services
,
hystrix将抛出异常
org.springframework.web.client.ResourceAccessException:I / O错误 GET请求“http://localhost:8081/services”:拒绝连接: 连接;嵌套异常是java.net.ConnectException:Connection 拒绝:连接
但我除外的是要调用的后备方法,有人可以告诉我出了什么问题吗?
码
@Component
public class hystrixServices {
private Random random = new Random();
public Logger loggers = Logger.getLogger(hystrixServices.class);
/**
* 模拟获取用户信息(通过网络调用)
* @return
*/
@HystrixCommand(fallbackMethod="fallback",
commandProperties = {
@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds", value="10000")
}
)
//@HystrixCommand(fallbackMethod="fallback")
public String mockGetUserInfo(){
try
{
int randomInt= random.nextInt(10) ;
if(randomInt<8){
customRestTemplate crt = new customRestTemplate();
RestTemplate rt = crt.getcustomRestTemplate();
loggers.info("start making the call");
String result = rt.getForObject("http://localhost:8081/services", String.class);
loggers.info("end making the call");
//loggers.info(result);
return result;
//return "random < 8";
}else{
return "UserName:liaokailin;number:"+randomInt;
}
}
catch(Exception e)
{
loggers.info(e.toString());
return "point 1:" + e.toString();
}
}
public String fallback(){
return "some exception occur call fallback method.";
}
}