【发布时间】:2017-01-13 00:27:06
【问题描述】:
根据文档,当使用 Feign 和 Hystrix 时,每个请求都会包装到一个 Hystrix 命令中。
是否可以为这些命令设置 Hystrix 属性?我想做这样的事情:
@RequestMapping(commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "30000")})
List<Team> findAll();
或:
@FeignClient(name = "teams", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "30000")})
作为记录,我已经尝试过使用属性,但没有成功。这些正在工作:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=10000
hystrix.command.findAll.execution.timeout.enabled=false
hystrix.command.default.execution.timeout.enabled=false
但是这个没有:
hystrix.command.findAll.execution.isolation.thread.timeoutInMilliseconds=20000
确实,我们可以在HystrixCommandProperties 类中读入以下注释:
//this property name is now misleading. //TODO figure out a good way to deprecate this property name
this.executionTimeoutInMilliseconds = getProperty(propertyPrefix, key, "execution.isolation.thread.timeoutInMilliseconds", builder.getExecutionIsolationThreadTimeoutInMilliseconds(), default_executionTimeoutInMilliseconds);
编辑:我尝试使用 feign 的 Request.Option 但这些属性似乎没有传播到 hystrix。
【问题讨论】:
-
基于您尝试设置的属性,我假设您正在尝试处理一些请求超时,您有堆栈跟踪吗?是否涉及 Ribbon?
-
远程服务响应时间有点长,所以我得到了HystrixRuntimeException异常。
-
你只设置了
application.properties中的属性吗? -
我就是这么做的
-
@HystrixProperty仅适用于@HystrixCommand,不适用于@RequestMapping和@FeignClient。通常在application.properties中设置 hystrix 属性是可行的。您有时缺少hystrix.command.<command>前缀。也许您有一个示例项目或者可以在问题中添加更多代码?
标签: spring spring-cloud hystrix spring-cloud-netflix netflix-feign