获取 HystrixRuntimeException:函数超时且回退失败

问题描述 投票:0回答:2

我正在使用 hystrix 1.5.3 并在本地计算机中运行这段代码。

@HystrixCommand (groupKey = "BookService", commandKey = "BookService.BookDetail", commandProperties = {
            @HystrixProperty (name = EXECUTION_ISOLATION_STRATEGY, value = "THREAD"),
            @HystrixProperty (name = CIRCUIT_BREAKER_ENABLED, value = "true"),
            @HystrixProperty (name = EXECUTION_TIMEOUT_ENABLED, value = "true"),
            @HystrixProperty (name = EXECUTION_ISOLATION_THREAD_TIMEOUT_IN_MILLISECONDS, value = "1500")}, threadPoolProperties = {
            @HystrixProperty (name = CORE_SIZE, value = "60"),
            @HystrixProperty (name = MAX_QUEUE_SIZE, value = "60"),
            @HystrixProperty (name = QUEUE_SIZE_REJECTION_THRESHOLD, value = "60"),
            @HystrixProperty (name = KEEP_ALIVE_TIME_MINUTES, value = "1")
    })
    public String getBookDetail(String bookId)
    {
       log.info("Getting details");
       ...
    }

在我们的服务器上它工作正常,但是我在本地计算机上遇到此运行时异常。我的本地服务器只是等待超时持续时间,最后抛出此 HystrixRuntimeException。另外,我没有定义任何后备,但我的情况不需要它。期望它应该像在我们的生产服务器中一样正常工作。

com.netflix.hystrix.exception.HystrixRuntimeException: BookService.BookDetail timed-out and fallback failed.
    at com.netflix.hystrix.AbstractCommand$21.call(AbstractCommand.java:793) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.AbstractCommand$21.call(AbstractCommand.java:768) ~[hystrix-core-1.5.3.jar:1.5.3]
    at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.onError(OperatorOnErrorResumeNextViaFunction.java:77) ~[rxjava-1.0.12.jar:1.0.12]
    at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70) ~[rxjava-1.0.12.jar:1.0.12]
    at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70) ~[rxjava-1.0.12.jar:1.0.12]
    at com.netflix.hystrix.AbstractCommand$DeprecatedOnFallbackHookApplication$1.onError(AbstractCommand.java:1448) ~[hystrix-core-1.5.3.jar:1.5.3]
    at com.netflix.hystrix.AbstractCommand$FallbackHookApplication$1.onError(AbstractCommand.java:1373) ~[hystrix-core-1.5.3.jar:1.5.3]
    at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70) ~[rxjava-1.0.12.jar:1.0.12]

我检查了该函数没有被执行,因为日志没有被打印。 当我通过修改

EXECUTION_ISOLATION_THREAD_TIMEOUT_IN_MILLISECONDS
来更改超时时,类似的行为会在新的超时持续时间之后发生。 当我删除 @HystrixCommand 注释时,它工作正常,因此这意味着仅 Hystrix 存在一些问题。 hystrix 属性似乎是在注释中定义的,看起来不错。难道是因为hystrix没有配置好?任何帮助将不胜感激。

java hystrix
2个回答
0
投票

您的函数在 1500 毫秒内未执行。

将 EXECUTION_TIMEOUT_ENABLED 更改为 false,hystrix 不会使你的方法超时。


0
投票

对我来说,这是一个 Spring 项目,问题在于

BookService.BookDetail
文件中未定义 commandKey(在本例中为
application.properties
)。下面的 123 值是任何数字的占位符:

hystrix.command.BookService.BookDetail.execution.isolation.thread.timeoutInMilliseconds=123
hystrix.command.BookService.BookDetail.circuitBreaker.errorThresholdPercentage=123
hystrix.command.BookService.BookDetail.circuitBreaker.requestVolumeThreshold=123
hystrix.BookService.BookDetail.circuitBreaker.sleepWindowInMilliseconds=123

似乎 OP 试图使用

@HystrixProperty
而不是
application.properties
文件来定义这些。也许属性名称有拼写错误。

© www.soinside.com 2019 - 2024. All rights reserved.