@FunctionalInterface public interface CircuitBreakerStrategy
Response should be reported as a success or a failure to a
CircuitBreaker. If you need to determine whether the request was successful by looking into the
Response content, use CircuitBreakerStrategyWithContent.| Modifier and Type | Method and Description |
|---|---|
static CircuitBreakerStrategy |
onServerErrorStatus()
Returns the
CircuitBreakerStrategy that determines a Response as successful
when its HttpStatus is not HttpStatusClass.SERVER_ERROR and there was no
Exception raised. |
static CircuitBreakerStrategy |
onStatus(BiFunction<HttpStatus,Throwable,Boolean> function)
Returns the
CircuitBreakerStrategy that determines a Response as successful
using the specified BiFunction. |
CompletionStage<Boolean> |
shouldReportAsSuccess(ClientRequestContext ctx,
Throwable cause)
Returns a
CompletionStage that contains true, false or
null which indicates a Response is successful or not. |
static CircuitBreakerStrategy onServerErrorStatus()
CircuitBreakerStrategy that determines a Response as successful
when its HttpStatus is not HttpStatusClass.SERVER_ERROR and there was no
Exception raised.static CircuitBreakerStrategy onStatus(BiFunction<HttpStatus,Throwable,Boolean> function)
CircuitBreakerStrategy that determines a Response as successful
using the specified BiFunction.function - the BiFunction that returns true, false or
null according to the HttpStatus and Throwable. If true
is returned, CircuitBreaker.onSuccess() is called so that the
CircuitBreaker increases its success count and uses it to make a decision to
close or open the circuit. If false is returned, it works the other way around.
If null is returned, the CircuitBreaker ignores it.CompletionStage<Boolean> shouldReportAsSuccess(ClientRequestContext ctx, Throwable cause)
CompletionStage that contains true, false or
null which indicates a Response is successful or not. If true is returned,
CircuitBreaker.onSuccess() is called so that the CircuitBreaker increases its success
count and uses it to make a decision to close or open the circuit. If false is returned, it works
the other way around. If null is returned, the CircuitBreaker ignores it.
To retrieve the ResponseHeaders, you can use the specified ClientRequestContext:
CompletionStage<Backoff> shouldReportAsSuccess(ClientRequestContext ctx, @Nullable Throwable cause) {
if (cause != null) {
return CompletableFuture.completedFuture(false);
}
ResponseHeaders responseHeaders = ctx.log().responseHeaders();
if (responseHeaders.status().codeClass() == HttpStatusClass.SERVER_ERROR) {
return CompletableFuture.completedFuture(false);
}
...
}
ctx - the ClientRequestContext of this requestcause - the Throwable which is raised while sending a request. null if there's no
exception.Copyright © 2020 LeanCloud. All rights reserved.