使用 Spring-Cloud-Config 而不是 Archaius 的 Hystrix 运行时配置?
Hystrix runtime configuration with Spring-Cloud-Config instead of Archaius?
我正在研究Spring-Cloud-Netflix,我了解到Archaius 用于Hystrix 运行时配置。 (https://ahus1.github.io/hystrix-examples/manual.html#archaius)
我还发现 Archaius 从 V1.5.0 (https://github.com/Netflix/Hystrix/pull/1083) 开始就是一个软依赖:"Archaius is now a soft-dependency of Hystrix, so you can supply your own configuration mechanism."
我的问题是,在运行时使用 Spring-Cloud-Config 配置 Hystrix 容易吗?我做了一些研究,但没有找到任何例子。
感谢任何想法。
经过几天的研究,我设法使用 Spring Cloud Config 动态配置 Hystrix 属性。我还做了一个关于在运行时配置 Hystrix 实例的小演示 属性。
首先,each Hystrix property has four levels of precendence:
- 全局默认
- 动态全局默认值
- 实例默认值
- 动态实例属性.
其中第1级和第3级仅支持静态配置。由于第二级(dynamic global default)在 Hystrix Wiki 中没有太多讨论,我选择 Dynamic Instance 属性运行时配置。但是,我相信我的方法也应该适用于 Dynamic Global Default。
做法很简单。首先使用@Value 注释从 Spring Cloud Config 中提取一个配置值:
@Value("{timeoutInMilliseconds:1500}")
String timeout;
然后在您的 Hystrix 实例中使用字符串 timeout
:
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixHelloWorld.execution.isolation.thread.timeoutInMilliseconds", timeout);
其中ConfigurationManager.getConfigInstance()
是一个Archaius method,returns是一个配置实例。 .setProperty()
设置 属性
我正在研究Spring-Cloud-Netflix,我了解到Archaius 用于Hystrix 运行时配置。 (https://ahus1.github.io/hystrix-examples/manual.html#archaius)
我还发现 Archaius 从 V1.5.0 (https://github.com/Netflix/Hystrix/pull/1083) 开始就是一个软依赖:"Archaius is now a soft-dependency of Hystrix, so you can supply your own configuration mechanism."
我的问题是,在运行时使用 Spring-Cloud-Config 配置 Hystrix 容易吗?我做了一些研究,但没有找到任何例子。
感谢任何想法。
经过几天的研究,我设法使用 Spring Cloud Config 动态配置 Hystrix 属性。我还做了一个关于在运行时配置 Hystrix 实例的小演示 属性。
首先,each Hystrix property has four levels of precendence:
- 全局默认
- 动态全局默认值
- 实例默认值
- 动态实例属性.
其中第1级和第3级仅支持静态配置。由于第二级(dynamic global default)在 Hystrix Wiki 中没有太多讨论,我选择 Dynamic Instance 属性运行时配置。但是,我相信我的方法也应该适用于 Dynamic Global Default。
做法很简单。首先使用@Value 注释从 Spring Cloud Config 中提取一个配置值:
@Value("{timeoutInMilliseconds:1500}")
String timeout;
然后在您的 Hystrix 实例中使用字符串 timeout
:
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixHelloWorld.execution.isolation.thread.timeoutInMilliseconds", timeout);
其中ConfigurationManager.getConfigInstance()
是一个Archaius method,returns是一个配置实例。 .setProperty()
设置 属性