I am using Resilience4j Circuit breaker version: '1.4.0 with Spring boot version 2.0.6 and my problem is - fallback method is not working. the call is not going to the fallback method. Below is my code :
@Override
@CircuitBreaker(name="mainService",fallbackMethod = "callFallback")
public JSONObject callService(JSONObject rawRequest) throws TimeoutException {
...
throw new TimeoutException("Time occured while calling
service");
...
}
-- and fallback method :
private JSONObject callFallback(JSONObject rawRequest,Throwable t){
System.out.println("Inside fallback method callNsFallback,
cause"+t.toString());
logger.info("Inside fallback method callFallback,
cause - {}",t.toString());
return rawRequest;
}
--Configurations in application.yml
resilience4j:
circuitbreaker:
configs:
default:
registerHealthIndicator: true
ringBufferSizeInClosedState: 5
ringBufferSizeInHalfOpenState: 3
slidingWindowSize: 10
minimumNumberOfCalls: 5
permittedNumberOfCallsInHalfOpenState: 3
automaticTransitionFromOpenToHalfOpenEnabled: true
waitDurationInOpenState: 1s
failureRateThreshold: 50
eventConsumerBufferSize: 10
recordExceptions:
- java.util.concurrent.TimeoutException
instances:
mainService:
baseConfig: default