Interface RetryStrategy
- 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 RetryStrategy
Determines whether a failed request should be retried.
If you need to determine by looking into the
Response
, use RetryStrategyWithContent
.-
Method Summary
Modifier and Type Method Description static RetryStrategy
never()
Returns aRetryStrategy
that never retries.static RetryStrategy
onException()
static RetryStrategy
onException(Function<? super Throwable,? extends Backoff> backoffFunction)
Returns aRetryStrategy
that decides to retry using the specifiedbackoffFunction
.static RetryStrategy
onServerErrorStatus()
Returns aRetryStrategy
that retries with theBackoff.ofDefault()
when the response status is 5xx (server error) or anException
is raised.static RetryStrategy
onServerErrorStatus(Backoff backoff)
Returns theRetryStrategy
that retries the request with the specifiedbackoff
when the response status is 5xx (server error) or anException
is raised.static RetryStrategy
onStatus(BiFunction<? super HttpStatus,? super Throwable,? extends Backoff> backoffFunction)
Returns aRetryStrategy
that decides to retry using the specifiedbackoffFunction
.static RetryStrategy
onUnprocessed()
Returns aRetryStrategy
that retries withBackoff.ofDefault()
only on anUnprocessedRequestException
.static RetryStrategy
onUnprocessed(Backoff backoff)
Returns aRetryStrategy
that retries with the specifiedBackoff
only on anUnprocessedRequestException
.CompletionStage<Backoff>
shouldRetry(ClientRequestContext ctx, Throwable cause)
Tells whether the request sent with the specifiedClientRequestContext
requires a retry or not.
-
Method Details
-
never
Returns aRetryStrategy
that never retries. -
onUnprocessed
Returns aRetryStrategy
that retries withBackoff.ofDefault()
only on anUnprocessedRequestException
. -
onUnprocessed
Returns aRetryStrategy
that retries with the specifiedBackoff
only on anUnprocessedRequestException
. -
onException
-
onException
Returns aRetryStrategy
that decides to retry using the specifiedbackoffFunction
. -
onServerErrorStatus
Returns aRetryStrategy
that retries with theBackoff.ofDefault()
when the response status is 5xx (server error) or anException
is raised. -
onServerErrorStatus
Returns theRetryStrategy
that retries the request with the specifiedbackoff
when the response status is 5xx (server error) or anException
is raised. -
onStatus
static RetryStrategy onStatus(BiFunction<? super HttpStatus,? super Throwable,? extends Backoff> backoffFunction)Returns aRetryStrategy
that decides to retry using the specifiedbackoffFunction
.- Parameters:
backoffFunction
- ABiFunction
that returns theBackoff
ornull
(no retry) according to the givenHttpStatus
andThrowable
-
shouldRetry
Tells whether the request sent with the specifiedClientRequestContext
requires a retry or not. Implement this method to return aCompletionStage
and to complete it with a desiredBackoff
. To stop trying further, complete it withnull
.To retrieve the
ResponseHeaders
, you can use the specifiedClientRequestContext
:CompletionStage<Backoff> shouldRetry(ClientRequestContext ctx, @Nullable Throwable cause) { if (cause != null) { return CompletableFuture.completedFuture(backoff); } ResponseHeaders responseHeaders = ctx.log().responseHeaders(); if (responseHeaders.status().codeClass() == HttpStatusClass.SERVER_ERROR) { return CompletableFuture.completedFuture(backoff); } ... }
- Parameters:
ctx
- theClientRequestContext
of this requestcause
- theThrowable
which is raised while sending a request.null
it there's no exception.
-