Hystrix在运行时忽略超时 [英] Hystrix ignores timeout on run

查看:204
本文介绍了Hystrix在运行时忽略超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试Hystrix。

I'm experimenting with Hystrix a little.

我支持文档,即使通过'run'同时调用Hystrix命令也默认运行一个线程,应该受Hystrix配置的超时限制。但是当我尝试它时,似乎没有超时。

I under stand the documentation such that even a synchronous call to a Hystrix command via 'run' runs by default in a thread and should be subject to the timeout configured in Hystrix. But when I try it, no timeout seems to happen.

我是否误解了文档?或者我做错了什么?有没有办法通过同步调用获得超时行为?

更具体:我有一个'SimpleService'需要5秒才能返回。这包含在Hystrix命令中,超时为500毫秒:

More specific: I have a 'SimpleService' that takes 5 seconds to return. This is wrapped in a Hystrix command with a timeout of 500ms:

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秒后得到结果=>没有超时

I get the result after 5 Seconds => No timeout

如果我这样称呼:

WebRequestCommand webService = new WebRequestCommand(baneService);
result = webService.queue().get();

Hystrix超时在500ms后发生并返回后备。

Hystrix timeout happens after 500ms and returns the fallback.

推荐答案

我认为应该以同步方式调用execute()而不是run()。

I think you should call execute() instead of run() for the synchronous way.

这篇关于Hystrix在运行时忽略超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆