Alex.Bai Alex.Bai - 1 year ago 444
Java Question

Hystrix runtime configuration with Spring-Cloud-Config instead of Archaius?

I'm studying Spring-Cloud-Netflix and I learned that Archaius was used for Hystrix runtime configuration. (

I also found that Archaius was a soft-dependency since V1.5.0 ( "Archaius is now a soft-dependency of Hystrix, so you can supply your own configuration mechanism."

My question is, is it easy to configure Hystrix with Spring-Cloud-Config at runtime? I did some research but haven't found any examples.

Appreciate any ideas.

Answer Source

After several days' research, I managed to dynamically configure Hystrix properties with Spring Cloud Config. I also made a small demo on configuring the Hystrix instance property at runtime.

First, each Hystrix property has four levels of precendence:

  1. Global default
  2. Dynamic global default
  3. Instance default
  4. Dynamic instance property.

Where the 1st and 3rd levels only support static configurations. Since the 2nd level (dynamic global default) was not discussed a lot in the Hystrix Wiki, I choose the Dynamic Instance Property for runtime configuration. However, I believe my method should apply to Dynamic Global Default as well.

The practice is simple. First pull a config value from Spring Cloud Config using the @Value annotation:

String timeout;

Then use the string timeout in your Hystrix instance:

Configurationmanager.getConfigInstance().setProperty("hystrix.command.HystrixHelloWorld.execution.isolation.thread.timeoutInMilliseconds", timeout);

Where the Configurationmanager.getConfigInstance() is an Archaius method, returns a configuration instance. .setProperty() sets the property

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download