I am working with resilience4j and spring boot,
I need to accomplish the below scenario,
- When I have a failure in the originalMethod
- After 5 attempts route to the fallback method
- After a specific time like 5 minutes return back to the originalMethod
I tried with retry as below but does not fit the problem ,
@Retry(name = "retryService", fallbackMethod = "fallback")
public String originalMethod(String data) throws InterruptedException {
//..... call external service
}
public String fallback(String data, Throwable t) {
logger.error("Inside retryfallback, cause – {}", t.toString());
return "Inside retryfallback method. Some error occurred ";
}
Added properties
resilience4j.retry:
instances:
retryService:
maxRetryAttempts: 5
waitDuration: 50000
CodePudding user response:
I think you can use a circuit breaker for sometime when a failure limit reached to achieve the behavior you want.
By adding @CircuitBreaker(...) annotation and specifying the failureRateThreshold, waitDurationInOpenState and the other needed config properties for that instance.