Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. (https://ahus1.github.io/hystrix-examples/manual.html#archaius)

I also found that Archaius was a soft-dependency since V1.5.0 (https://github.com/Netflix/Hystrix/pull/1083): "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.

like image 624
Alex.Bai Avatar asked Dec 02 '25 13:12

Alex.Bai


1 Answers

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:

@Value("{timeoutInMilliseconds:1500}")
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

like image 171
Alex.Bai Avatar answered Dec 05 '25 04:12

Alex.Bai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!