I want to use a fallback in case of failing, so the behavior in "open" state should be to call a fallback instead of throwing an exception.
Problem is that the fallback is called during the "closed" state, while for "open" state I still get the exception. Is this the intended behavior? No way to attain what I am searching for?
I have defined my custom circuit break:
resilience4j:
circuitbreaker:
configs:
default:
register-health-indicator: true
slidingWindowSize: 10
minimumNumberOfCalls: 2
permittedNumberOfCallsInHalfOpenState: 2
automaticTransitionFromOpenToHalfOpenEnabled: true
waitDurationInOpenState: 20s
failureRateThreshold: 20
slowCallDurationThreshold: 2s
slowCallRateThreshold: 20
instances:
backendA:
base-config: default
Now, I defined my method as follows:
public class ExampleService {
@CircuitBreaker(name = "default", fallbackMethod = "fall")
public List<String> doSomething(Long id) {
return Arrays.asList("a", "b", "c");
}
private List<String> fall(Long id, Exception ex) {
return Arrays.asList("faaaallingggg");
}
}
Just change your signature of the fallback method to
private List<String> fall(Long id, CallNotPermittedException ex) {
return Arrays.asList("faaaallingggg");
}