我正在尝试使用 Hystrix。
我理解文档,即使通过“运行”同步调用 Hystrix 命令也会默认在线程中运行,并且应该受到 Hystrix 中配置的超时的影响。但当我尝试时,似乎没有发生超时。
我是否误解了文档?或者我做错了什么?有没有办法通过同步调用获得超时行为?
更具体地说:我有一个“SimpleService”,需要 5 秒才能返回。这是包含在超时为 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 毫秒后并返回回退。
我认为你应该以同步方式调用execute()而不是run()。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)