Interface CircuitBreakerRule

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface CircuitBreakerRule
Determines whether a Response should be reported as a success or failure to a CircuitBreaker. If you need to determine whether the request was successful by looking into the Response content, use CircuitBreakerRuleWithContent.

Note that if the last CircuitBreakerRule completes with CircuitBreakerDecision.next() or a Response is not matched with the CircuitBreakerRules, then the Response will be reported as a success.

For example:


 // If a response status is 500(Interval Server Error), the response will be reported as a failure.
 // Otherwise, the response will be reported as a success.
 CircuitBreakerRule.onStatus(HttpStatus.INTERNAL_SERVER_ERROR);

 // A response will be reported as a success if no exception is raised.
 CircuitBreakerRule.onException();

 // A CircuitBreakerRule that reports a response as a failure except that a response status code is 2xx.
 CircuitBreakerRule.of(
         // Report as a success if the class of a response status is 2xx
         CircuitBreakerRule.builder()
                           .onStatusClass(HttpStatusClass.SUCCESS)
                           .thenSuccess(),
         // Everything else is reported as a failure
         ClientBreakerRule.builder().thenFailure());