Ale*_*Bai 2 java netflix hystrix spring-cloud
我正在研究Spring-Cloud-Netflix,我了解到Archaius用于Hystrix运行时配置.(https://ahus1.github.io/hystrix-examples/manual.html#archaius)
我还发现自从V1.5.0(https://github.com/Netflix/Hystrix/pull/1083)以来,Archaius是一个软依赖:"Archaius现在是Hystrix的软依赖,所以你可以提供自己的配置机制."
我的问题是,在运行时使用Spring-Cloud-Config配置Hystrix是否容易?我做了一些研究,但没有找到任何例子.
欣赏任何想法.
经过几天的研究,我设法用Spring Cloud Config动态配置Hystrix属性.我还做了一个关于在运行时配置Hystrix实例属性的小型演示.
第1级和第3级仅支持静态配置.由于Hystrix Wiki中没有对第二级(动态全局默认值)进行过多讨论,因此我为运行时配置选择了动态实例属性.但是,我相信我的方法也应该适用于Dynamic Global Default.
这种做法很简单.首先使用@Value注释从Spring Cloud Config中提取配置值:
@Value("{timeoutInMilliseconds:1500}")
String timeout;
Run Code Online (Sandbox Code Playgroud)
然后timeout在Hystrix实例中使用该字符串:
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixHelloWorld.execution.isolation.thread.timeoutInMilliseconds", timeout);
Run Code Online (Sandbox Code Playgroud)
如果ConfigurationManager.getConfigInstance()是Archaius方法,则返回配置实例..setProperty()设置属性
| 归档时间: |
|
| 查看次数: |
1937 次 |
| 最近记录: |