首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hystrix不抛出HystrixRuntimeException,而是空消息错误。

Hystrix不抛出HystrixRuntimeException,而是空消息错误。
EN

Stack Overflow用户
提问于 2017-10-31 13:15:00
回答 1查看 4K关注 0票数 1

我在服务层的spring引导应用程序中使用Hystrix (version Camden.SR7 of spring-cloud-dependencies),没有后备方法。服务的一个方法如下所示:

代码语言:javascript
复制
@HystrixCommand(commandKey = "prefs",
        commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")})
@Override
public void savePrefs(PrefsRequestParams requestParams) throws Exception {
    ...
}

如果该方法执行时间超过2秒,Hystrix将抛出java.util.concurrent.TimeoutException: null,REST响应如下所示:

代码语言:javascript
复制
{
    "timestamp": 1509452672714,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "java.util.concurrent.TimeoutException",
    "message": "No message available",
    "path": "/prefs"
}

对于这样的响应,还不清楚是从哪种方法异常引发的。如果我将spring-cloud-dependencies版本更改为Brixton.SR5 (以前的版本),它将返回明确的响应:

代码语言:javascript
复制
{
    "timestamp": 1509452426819,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "com.netflix.hystrix.exception.HystrixRuntimeException",
    "message": "prefs timed-out and fallback failed.",
    "path": "/prefs"
}

因此,新版本的Hystrix (实际上是spring依赖关系的新版本)不会抛出。这是一个错误,还是应该以另一种方式配置Hystrix以接收清楚的消息错误?

我使用以下maven依赖项:

代码语言:javascript
复制
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
    <version>1.2.7.RELEASE</version>
</dependency>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Camden.SR7</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
     ...

从maven依赖树中可以看出,它使用com.netflix.hystrix:hystrix-core:jar:1.5.6:compile表示spring-cloud-dependencies版本Camden.SR7,以及版本Brixton.SR5 - com.netflix.hystrix:hystrix-core:jar:1.5.3:compile

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-31 13:52:53

更新到Javanica 1.5.12可以解决这个问题。

在1.5.7中,还有一个选项可以强制抛出所有未被忽略的异常的HystrixRuntimeException:

代码语言:javascript
复制
@HystrixCommand(raiseHystrixExceptions = {HystrixException.RUNTIME_EXCEPTION})
@Override
public void savePrefs(PrefsRequestParams requestParams) throws Exception {
    ...
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47036396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档