2

I use the Hystrix-Javanica library to apply the circuit breaker via annotations. I'd like to configure Hystrix with properties defined in the Spring configuration. Since my application uses Spring AOP, I hoped something like this would work:

@HystrixCommand(commandProperties = {
  @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "${cb.requestVolumeThreshold}")
})
public boolean checkWebservice(String id) { ... }

But this fails with bad property value. property name 'circuitBreaker.requestVolumeThreshold'. Expected int value

Any ideas how I can configure Hystrix without hard coding the values?

Tim Van Laer
  • 2,434
  • 26
  • 30
  • you can also follow this... https://stackoverflow.com/questions/31211685/configuring-hystrix-command-properties-using-application-yaml-in-spring-boot-app – akash777.sharma Sep 20 '19 at 10:03

1 Answers1

5

Using property placeholders inside the Hystrix annotations didn't work out.

Instead I chose to define the full configuration properties, e.g.:

hystrix.command.checkWebservice.circuitBreaker.requestVolumeThreshold=10

And I added this Spring Configuration class to load spring properties into Archaius:

@Configuration
public class HystrixConfig {

    @Autowired
    private CommonsConfigurationFactoryBean props;

    @PostConstruct
    public void init() {
        ConfigurationManager.install(props.getConfiguration());
    }
}

Spring Cloud Netflix may be an alternative for this setup, but it requires Spring Boot.

Tim Van Laer
  • 2,434
  • 26
  • 30
  • For me the ConfigurationManager.install(props.getConfiguration()); replaced some important properties. In my case I had to do ConfigurationManager.loadPropertiesFromConfiguration(props.getConfiguration()); and everything worked. Thank you! – Glenn Van Schil Apr 08 '21 at 12:54