0

I want to predefine global configuration for all the hystrix commands in my project. I.e. I want to mark methods only with something like this:

@HystrixCommand(commandKey = "MFO_SERVICE", fallbackMethod = "fallback")

not like this

@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")

And all the params should be stored at property file and should be able to change without re-compiling. So I'm trying to use a spring component that takes a param from enironment and injects it into the 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);
  }
}

But it takes no effect. It seems to be no hystrix command exists at Spring @PostConstruct moment. And finally I got a HystrixCommand with default config.

Is there any way to resolve it?

kirill.login
  • 899
  • 1
  • 13
  • 28

1 Answers1

0

By default, Archaius look for configuration properties from “config.properties” on the application’s classpath. So define all properties in config.properties file with your command key and use that commant key in @HystrixCommand.

for more info https://medium.com/@aksudupa11/getting-started-with-hystrix-e454158f2867

Vikash Kumar Verma
  • 1,068
  • 2
  • 14
  • 30