Search code examples
javahystrixcircuit-breaker

Programmatically changing Hystrix properties


I have a circuit breaker set up that I would like to change parameters for runtime. Things like threads and timeout needs to be tuned at customer site.

I create a HystrixCommandProperties.Setter like this:

HystrixCommandProperties.Setter hystrixProps = 
    HystrixCommandProperties.defaultSetter()
        .withCircuitBreakerSleepWindowInMilliseconds(myconf.sleepWindow);
HystrixThreadPoolProperties.Setter threadPoolSettings = 
    HystrixThreadPoolProperties.Setter()
        .withCoreSize(myconf.threadPoolSize);

new MyCommand(HystrixCommand.Setter.withGroupKey("mygroup")
    .andCommandPropertiesDefaults(hystrixProps)
    .andThreadPoolPropertiesDefaults(threadPoolSettings));

MyCommand implements standard HystrixCommand and calls super(hystrixProps).

This works the first time, but when I try to change the properties at runtime (same group name) nothing happens. Is there another way to programmatically change this?

I don't want to go through the property files or specifying an URL to Archaius.

There are also answers that tells me to go through Archaius with ConfigurationManager.getConfigInstance().setProperty("...") . But surely there has to be a way that is similar to the original setters I create? Doing it completely different because it's the second time around just feels awkward.


Solution

  • For future reference: I ended up using the settings through ConfigurationManager and a string property.

    ConfigurationManager.getConfigInstance().setProperty("...")
    

    It let's me change things, but in a less type-safe way than the original code. I did struggle for some time with a typo in the string which is why I'd like to avoid that.

    I now use this for all the properties I need to change runtime. Creating a new Hystrix circuit breaker every time something changes (new command key) could be an option as well, but would break using properties files later on.