【发布时间】:2015-03-03 03:15:16
【问题描述】:
我正在尝试一些 Hystrix。
我理解文档,即使通过“运行”对 Hystrix 命令的同步调用默认在线程中运行,并且应该受 Hystrix 中配置的超时限制。但是当我尝试它时,似乎没有发生超时。
我是否误解了文档?还是我做错了什么?有没有办法通过同步调用获得超时行为?
更具体地说:我有一个需要 5 秒才能返回的“SimpleService”。这包含在一个超时为 500 毫秒的 Hystrix 命令中:
public class WebRequestCommand extends HystrixCommand<String> {
private final SimpleService baneService;
protected WebRequestCommand(SimpleService baneService) {
super(
Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("test"))
.andCommandPropertiesDefaults(
HystrixCommandProperties.Setter()
.withExecutionIsolationThreadTimeoutInMilliseconds(500)));
this.baneService = baneService;
}
@Override
protected String run() {
return baneService.connectToBane();
}
@Override
protected String getFallback() {
return "SERVICE NOT AVAILABLE";
}
}
如果我这样称呼它:
WebRequestCommand webService = new WebRequestCommand(baneService);
result = webService.run();
我在 5 秒后得到结果 => 没有超时
如果我这样称呼它:
WebRequestCommand webService = new WebRequestCommand(baneService);
result = webService.queue().get();
Hystrix 超时发生在 500 毫秒后并返回回退。
【问题讨论】:
标签: java configuration timeout hystrix