Hystrix ignores timeout on run

爱⌒轻易说出口 提交于 2019-12-22 10:58:50

问题


I'm experimenting with Hystrix a little.

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.

Do I misinterpret the documentation? Or am I doing something wrong? And is there a way to get the timeout behavior with synchronous calls?

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";
    }
}

If I call it like this:

WebRequestCommand webService = new WebRequestCommand(baneService);
result = webService.run();

I get the result after 5 Seconds => No timeout

If I call it like this:

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

Hystrix timeout happens after 500ms and returns the fallback.


回答1:


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



来源:https://stackoverflow.com/questions/27781982/hystrix-ignores-timeout-on-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!