I have circuitbreaker implemented in my springboot application. I have used following dependency:
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j'
And I have following properties configured for my testing:
resilience4j:
circuitbreaker:
instances:
myEventCircuitBreaker:
minimum-number-of-calls: 6
failure-rate-threshold: 80
automatic-transition-from-open-to-half-open-enabled: true
wait-duration-in-open-state: 300s
permitted-number-of-calls-in-half-open-state: 4
sliding-window-size: 1000
sliding-window-type: count_based
When I test in my local it works fine, where in case of exception after 6 events, circuit is opened.
And after 300seconds (5 minutes) circuitbreaker goes in half open state.
I have following logs configured:
@Slf4j
@Configuration
public class CircuitBreakerConfig {
private final BindingsLifecycleController bindingsLifecycleController;
public CircuitBreakerConfig(CircuitBreakerRegistry circuitBreakerRegistry, BindingsLifecycleController bindingsLifecycleController) {
this.bindingsLifecycleController = bindingsLifecycleController;
CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker("myEventCircuitBreaker");
circuitBreaker.getEventPublisher()
.onStateTransition(this::handleStateTransition);
}
private void handleStateTransition(CircuitBreakerOnStateTransitionEvent event) {
String bindingName = "stockEventConsumer-in-0";
switch (event.getStateTransition().getToState()) {
case OPEN:
log.info("circuitbreaker state:: open");
bindingsLifecycleController.changeState(bindingName, State.PAUSED);
break;
case HALF_OPEN:
log.info("circuitbreaker state:: half_open");
bindingsLifecycleController.changeState(bindingName, State.RESUMED);
break;
case CLOSED:
log.info("circuitbreaker state:: closed");
bindingsLifecycleController.changeState(bindingName, State.RESUMED);
break;
default:
log.error("circuitbreaker unknown state");
}
}
}
The issue what I am facing is when I deploy my code in my dev/ppe environment, after 6 events with exception I am getting circuit open log.
But after that its not moving to half open state, and I don’t see any logs from the configuration.
I read somewhere to add aspectj
dependency, and after adding that, still its not working in the dev/ppe environment. But working as expected in local.
implementation 'org.aspectj:aspectjrt:1.9.7'
implementation 'org.aspectj:aspectjweaver:1.9.7'