【问题标题】:How to predefine hystrix command configuration如何预定义hystrix命令配置
【发布时间】: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


    【解决方案1】:

    默认情况下,Archaius 从应用程序类路径的“config.properties”中查找配置属性。因此,使用您的命令键定义 config.properties 文件中的所有属性,并在 @HystrixCommand 中使用该命令键。

    更多信息https://medium.com/@aksudupa11/getting-started-with-hystrix-e454158f2867

    【讨论】:

      猜你喜欢
      • 2015-03-16
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      • 2018-02-23
      • 2018-07-15
      • 2018-09-12
      • 2018-08-01
      相关资源
      最近更新 更多