如何使用 spring 云将 Hystrix 属性设置为 Feign 请求?
How to set set a HystrixProperty to a Feign request with spring cloud?
根据文档,当将 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
class:
//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。
问题已解决:这是一个编码问题。我有 copied/pasted 文档中的一行,但它不是 UTF-8 编码的(尽管 STS 的显示是正确的)。
您也可以像下面这样以编程方式设置属性。
ConfigurationManager.getConfigInstance()
.setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", 1500);
根据文档,当将 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
class:
//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。
问题已解决:这是一个编码问题。我有 copied/pasted 文档中的一行,但它不是 UTF-8 编码的(尽管 STS 的显示是正确的)。
您也可以像下面这样以编程方式设置属性。
ConfigurationManager.getConfigInstance()
.setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", 1500);