Interface CircuitBreakerStrategy
- 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 CircuitBreakerStrategy
Determines whether a
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
.-
Method Summary
Modifier and Type Method Description static CircuitBreakerStrategy
onServerErrorStatus()
Returns theCircuitBreakerStrategy
that determines aResponse
as successful when itsHttpStatus
is notHttpStatusClass.SERVER_ERROR
and there was noException
raised.static CircuitBreakerStrategy
onStatus(BiFunction<HttpStatus,Throwable,Boolean> function)
Returns theCircuitBreakerStrategy
that determines aResponse
as successful using the specifiedBiFunction
.CompletionStage<Boolean>
shouldReportAsSuccess(ClientRequestContext ctx, Throwable cause)
Returns aCompletionStage
that containstrue
,false
ornull
which indicates aResponse
is successful or not.
-
Method Details
-
onServerErrorStatus
Returns theCircuitBreakerStrategy
that determines aResponse
as successful when itsHttpStatus
is notHttpStatusClass.SERVER_ERROR
and there was noException
raised. -
onStatus
Returns theCircuitBreakerStrategy
that determines aResponse
as successful using the specifiedBiFunction
.- Parameters:
function
- theBiFunction
that returnstrue
,false
ornull
according to theHttpStatus
andThrowable
. Iftrue
is returned,CircuitBreaker.onSuccess()
is called so that theCircuitBreaker
increases its success count and uses it to make a decision to close or open the circuit. Iffalse
is returned, it works the other way around. Ifnull
is returned, theCircuitBreaker
ignores it.
-
shouldReportAsSuccess
CompletionStage<Boolean> shouldReportAsSuccess(ClientRequestContext ctx, @Nullable Throwable cause)Returns aCompletionStage
that containstrue
,false
ornull
which indicates aResponse
is successful or not. Iftrue
is returned,CircuitBreaker.onSuccess()
is called so that theCircuitBreaker
increases its success count and uses it to make a decision to close or open the circuit. Iffalse
is returned, it works the other way around. Ifnull
is returned, theCircuitBreaker
ignores it. To retrieve theResponseHeaders
, you can use the specifiedClientRequestContext
: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); } ... }
- Parameters:
ctx
- theClientRequestContext
of this requestcause
- theThrowable
which is raised while sending a request.null
if there's no exception.
-