question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New feture: open CircuitBreaker for a time based on the decorated calls response

See original GitHub issue

Problem:

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:open
  • Created 2 years ago
  • Reactions:6
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
walec51commented, Apr 21, 2021

@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

0reactions
walec51commented, Oct 10, 2021

@RobWin finally found some time to implement this, pls take a look at my draft PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing a Circuit Breaker with Resilience4j - Reflectoring
A count-based circuit breaker switches state from closed to open if the last N number of calls failed or were slow. A time-based...
Read more >
CircuitBreaker - resilience4j
The CircuitBreaker uses a sliding window to store and aggregate the outcome of calls. You can choose between a count-based sliding window and...
Read more >
How to Use Circuit Breaker in Spring Boot Application
In this post, I show how one can use COUNT based and TIME based circuit breaker in a spring boot application.
Read more >
Failover and Circuit Breaker with Resilience4j | by Rob Golder
The application is configured to use the circuit breaker pattern. If the number of failed calls to the primary 3PP within a given...
Read more >
How to Use Resilience4j to Implement Circuit Breaker?
The circuit breaker is a design pattern where you stop executing some code when the previous attempt(s) have failed. For example, calling web ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found