resilience4j: CircuitBreaker record a failure when a certain result is returned

Retry allows check the result of a call and retry a call when a configurable predicate is true. It would be nice if the CircuitBreaker allows it as well. CircuitBreakerConfig should allow to configure a result predicate.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 42 (33 by maintainers)

Commits related to this issue

Most upvoted comments

Throwing exception from CB is not a good option in my case, that’s way I need global result predicate. I need CB to count some results as failures but not to throw an exception in that case. When a result predicate is configured CB should throw exception only when its state is open.

My idea would be to pass the an optional result here:

https://github.com/resilience4j/resilience4j/blob/master/resilience4j-circuitbreaker/src/main/java/io/github/resilience4j/circuitbreaker/CircuitBreaker.java#L558

Then create a function to handle it, similar as:

https://github.com/resilience4j/resilience4j/blob/master/resilience4j-circuitbreaker/src/main/java/io/github/resilience4j/circuitbreaker/internal/CircuitBreakerStateMachine.java#L209

For the exception I was thinking in create something like ResultRecordedAsFailureException and pass it at the end.

The change will have a lot of collateral changes, I know, but I can not see a better way to do it.

Let me create the PR, let’s see how it looks like, you can discard it, no personal attachment to the code, no worries … again is going to be huge, but we should be covered by tests

Creating a PR, it is going to be huge!

@RobWin I’m working on this right now. I will make a PR soon!

You can easily implement this feature with a simple higher-order function. Actually no need for a onResult predicate. The advantage is that you can have different onResult checks per decorated method.

Higher-order functions are really powerful.