【问题标题】:Hystrix runtime configuration with Spring-Cloud-Config instead of Archaius?使用 Spring-Cloud-Config 而不是 Archaius 的 Hystrix 运行时配置?
【发布时间】:2016-06-30 06:41:31
【问题描述】:

我正在研究 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 现在是 Hystrix 的软依赖,所以你可以提供自己的配置机制。”

我的问题是,在运行时使用 Spring-Cloud-Config 配置 Hystrix 是否容易?我做了一些研究,但没有找到任何例子。

欣赏任何想法。

【问题讨论】:

    标签: java spring-cloud netflix hystrix


    【解决方案1】:

    经过几天的研究,我设法使用 Spring Cloud Config 动态配置 Hystrix 属性。我还做了一个关于在运行时配置 Hystrix 实例属性的小演示。

    首先,each Hystrix property has four levels of precendence

    1. 全局默认值
    2. 动态全局默认值
    3. 实例默认值
    4. 动态实例属性。

    第 1 层和第 3 层仅支持静态配置。由于在 Hystrix Wiki 中没有对第二级(动态全局默认)进行大量讨论,因此我选择 Dynamic Instance Property 进行运行时配置。不过,我相信我的方法也应该适用于 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,则返回一个配置实例。 .setProperty() 设置属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 2019-03-20
      • 2018-08-03
      • 2016-12-12
      • 2016-01-10
      • 2017-01-06
      • 1970-01-01
      相关资源
      最近更新 更多