[英]Hystrix does not throw HystrixRuntimeException, and instead empty message error
I use Hystrix (version Camden.SR7 of spring-cloud-dependencies
) in spring-boot app on service layer without fallback methods. 我在服务层上的spring-boot应用程序中使用Hystrix( spring-cloud-dependencies
Camden.SR7版本),没有后备方法。 One of service's method looks like the following: 服务的一种方法如下所示:
@HystrixCommand(commandKey = "prefs",
commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")})
@Override
public void savePrefs(PrefsRequestParams requestParams) throws Exception {
...
}
If such method executes longer than 2 seconds, Hystrix will throw java.util.concurrent.TimeoutException: null, and REST response will look like: 如果此类方法执行的时间超过2秒,则Hystrix将抛出java.util.concurrent.TimeoutException:null,并且REST响应将如下所示:
{
"timestamp": 1509452672714,
"status": 500,
"error": "Internal Server Error",
"exception": "java.util.concurrent.TimeoutException",
"message": "No message available",
"path": "/prefs"
}
With such response it's unclear from which method exception actually was thrown. 对于这样的响应,尚不清楚实际上从哪个方法引发异常。 If I change spring-cloud-dependencies
version to Brixton.SR5 (previous version), it returns clear response: 如果将spring-cloud-dependencies
版本更改为Brixton.SR5(先前版本),它将返回明确的响应:
{
"timestamp": 1509452426819,
"status": 500,
"error": "Internal Server Error",
"exception": "com.netflix.hystrix.exception.HystrixRuntimeException",
"message": "prefs timed-out and fallback failed.",
"path": "/prefs"
}
So new version of Hystrix (actually new version of spring-cloud-dependencies) does not throw HystrixRuntimeException. 因此,Hystrix的新版本(实际上是spring-cloud-dependencies的新版本)不会引发HystrixRuntimeException。 Is it a bug or should I configure Hystrix in another way to receive clear message error? 是错误还是我应该以其他方式配置Hystrix来接收明确的消息错误?
I use the following maven dependencies: 我使用以下Maven依赖项:
<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>
...
from maven dependency tree I see that it uses com.netflix.hystrix:hystrix-core:jar:1.5.6:compile
for spring-cloud-dependencies
version Camden.SR7, and for version Brixton.SR5 - com.netflix.hystrix:hystrix-core:jar:1.5.3:compile
. 从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
。
Updating to Javanica 1.5.12 resolves the issue. 更新到Javanica 1.5.12可解决此问题。
From 1.5.7 there is also an option to force throwing HystrixRuntimeException for all not ignored exceptions: 从1.5.7版本开始,还有一个选项可以为所有未忽略的异常强制抛出HystrixRuntimeException:
@HystrixCommand(raiseHystrixExceptions = {HystrixException.RUNTIME_EXCEPTION})
@Override
public void savePrefs(PrefsRequestParams requestParams) throws Exception {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.