【发布时间】:2019-05-12 01:56:48
【问题描述】:
我想为我的项目中的所有 hystrix 命令预定义全局配置。 IE。我只想用这样的东西来标记方法:
@HystrixCommand(commandKey = "MFO_SERVICE", fallbackMethod = "fallback")
不是这样的
@HystrixCommand(
commandKey = "MFO_SERVICE",
commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "60000"),
@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "10"),
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "50"),
@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "60000")},
fallbackMethod = "fallback")
并且所有参数都应该存储在属性文件中,并且应该能够在不重新编译的情况下进行更改。所以我正在尝试使用一个弹簧组件,它从环境中获取一个参数并将其注入 Hystrix (Archaius) ConfigurationManager。
@Component
public class HystrixConfig {
@Value("${execution.isolation.thread.timeoutInMilliseconds}")
private String timeoutInMilliseconds;
@PostConstruct
private void init() {
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.MFO_SERVICE.execution.isolation.thread.timeoutInMilliseconds", timeoutInMilliseconds);
}
}
但它不起作用。在 Spring @PostConstruct 时刻似乎不存在 hystrix 命令。最后我得到了一个带有默认配置的 HystrixCommand。
有什么办法解决吗?
【问题讨论】:
标签: java spring configuration hystrix circuit-breaker