Resilience4j: Circuit breaker: evaluate response as a failure

Created on 25 Aug 2019  路  5Comments  路  Source: resilience4j/resilience4j

Hi,

I was checking the options for Circuit Breaker:
https://resilience4j.readme.io/docs/circuitbreaker

But I didn麓t see the possibility to evaluate a successful response as a failure. This possibility is available for another behaviour Retry:
https://resilience4j.readme.io/docs/retry

result -> false
Configures a Predicate which evaluates if a result should be retried. The Predicate must return true, if the result should be retried, otherwise it must return false.

Do you think that it is possible to add something similar in this behaviour?

Many thanks in advance.

Juan Antonio

All 5 comments

The simplest way is to throw an exception from your client (for the successful response you want to mark as failure) and put that exception in record exception list of circuit breaker.

Hi,
no, not yet.
I close this issue, because it's a duplicate of https://github.com/resilience4j/resilience4j/issues/384
Please have a look at the discussion.

We created a SupplierUtils which helps you in situations where you can't modify the client code.

```
Supplier supplier = () -> httpClient.doRemoteCall();
Supplier supplierWithResultHandling = SupplierUtils.andThen(supplier, result -> {
if (result.getStatusCode() == 400) {
throw new HttpClientServerException();
} else if (result.getStatusCode() == 500) {
throw new HttpServerException();
}
return result;
});
HttpResponse httpResponse = circuitBreaker
.executeSupplier(supplierWithResultHandling);
````

Many thanks, I will try this approach

Applied the solution and the usage is easy.

Was this page helpful?
0 / 5 - 0 ratings