resilience4j / resilience4j-spring-boot2-demo

A Spring Boot 2 demo which shows how to use the Resilience4j Spring Boot 2 Starter
Apache License 2.0
254 stars 190 forks source link

How to keep different CircuitBreakerConfiguration for multiple circuit breakers? #62

Open hmantri05 opened 2 years ago

hmantri05 commented 2 years ago

I have created a @Bean of CircuitBreakerRegistry and have annotated four different methods using @CircuitBreaker annotation. All have different names.

Screenshot 2022-04-21 at 9 35 44 AM Screenshot 2022-04-21 at 9 36 32 AM

I want to keep 4 different kinds of CircuitBreakerConfig in the registry for each of the circuit breaker.

How can I achieve this?

Also, I want to log every event on these four CircuitBreakers. I know we can achieve that using: registry.circuitBreaker(name).getEventPublisher().onEvent(logger)

But how do I get hold of the reference to those four circuit breakers?

@RobWin

RobWin commented 2 years ago

Hi why don't you use the Spring Boot starter and external configuration? Did you have a look at the demo?

RobWin commented 2 years ago

See link for event consumer registration.

https://github.com/resilience4j/resilience4j-spring-boot2-demo/blob/0aa908b522102ec0fae69f453fe580d8fd53103c/src/main/java/io/github/robwin/Application.java#L40

hmantri05 commented 2 years ago

@RobWin So we have an internal tool (CCM) where we keep the configs and which can be changed at runtime as well. The hardcoded values that I have shown in the above screenshot, I am going to feed those values from our CCM config classes. So I can't use the application.properties config here.

RobWin commented 2 years ago

Cannot you make use of Spring Cloud Config instead? It allows the reconfiguration at runtime. Otherwise how do you trigger a reconfiguration in Spring Boot?

hmantri05 commented 2 years ago

@RobWin So the application keeps on polling the CCM to see if there are any changes every minute. It's a company wide used tool. Inhouse built.

RobWin commented 2 years ago

But how do you refresh the Registry? Do you replace the CircuitBreaker instances?

hmantri05 commented 2 years ago

@RobWin The current use case is to have four diffent configs with which we can initialize the circuit breakers. For now there is no need to refresh the config at runtime. But that's a valid point. May be you can suggest something around refreshing the circuit breakers live as well. :D

RobWin commented 2 years ago

I would propose to use Spring Cloud Config and build an adapter around your internal CCM tool. Use the external config file to configure your 4 CircuitBreakers.