【发布时间】:2018-04-12 16:20:27
【问题描述】:
我在服务层的 spring-boot 应用程序中使用 Hystrix(spring-cloud-dependencies 的 Camden.SR7 版本),没有回退方法。服务的方法之一如下所示:
@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 响应将如下所示:
{
"timestamp": 1509452672714,
"status": 500,
"error": "Internal Server Error",
"exception": "java.util.concurrent.TimeoutException",
"message": "No message available",
"path": "/prefs"
}
对于这样的响应,不清楚实际是从哪个方法抛出异常。如果我将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"
}
所以新版Hystrix(其实是新版spring-cloud-dependencies)不会抛出HystrixRuntimeException。这是一个错误还是我应该以其他方式配置 Hystrix 以接收明确的消息错误?
我使用以下 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>
...
从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。
【问题讨论】:
标签: java spring-boot spring-cloud spring-cloud-netflix hystrix