New feture: open CircuitBreaker for a time based on the decorated calls response
See original GitHub issueProblem:
We have a client class that uses resiliance4j decorators. The underlining API, which the client calls, can ban our IP for some time for multiple reasons. The underlining API in its error response returns the duration of the given ban and expects that we will stop any further communication during it. Not doing so could result in an even longer ban.
Solution:
This is an ideal use case for a circuit breaker as the bans duration can exceed the period of any rate limiter that is also applied. However resilience4j circuit breaker lacks configuration options and some implementation mechanisms to handle this. Therefore I propose to add the following API:
CircuitBreakerConfig.from(...)
// ...
.forceOpenOnResult(Either<Throwable, T> result -> {
if (result.getLeft() instanceof SomeSpecificException) {
SomeSpecificException e = (SomeSpecificException) result.getLeft();
return ForceOpenChecksResult.neededUntil(e.getBannedUntil()); // Instant
}
return ForceOpenChecksResult.notNeeded();
})
.build()
ForceOpenChecksResult
could also have a creator method called ForceOpenChecksResult.needed()
that would force open the circuit breaker for the time configured in waitDurationInOpenState
attribute.
I’m willing to implement this feature if it will be accepted. We need this feature in this project: https://github.com/knowm/XChange where we already use resilience4j for rate limiting and retries.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:7 (7 by maintainers)
@RobWin yes, I have read all your suggestions and I agree with them, I just didn’t have the time to start working on this - maybe I’ll find some on this weekend
@RobWin finally found some time to implement this, pls take a look at my draft PR