Class RetryingHttpRequesterFilter.Builder
- Enclosing class:
- RetryingHttpRequesterFilter
RetryingHttpRequesterFilter
, which puts an upper bound on retry attempts.
To configure the maximum number of retry attempts see maxTotalRetries(int)
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a retryingRetryingHttpRequesterFilter
with this' builders configuration.ignoreServiceDiscovererErrors
(boolean ignoreSdErrors) By default, fail a request if the last signal from the associatedServiceDiscoverer
was an error.maxTotalRetries
(int maxRetries) Set the maximum number of allowed retry operations before giving up, applied as total max across all retry functions (see.onRequestRetry
(RetryingHttpRequesterFilter.RetryCallbacks onRequestRetry) Callback invoked on everyrequest
retry attempt.responseMapper
(Function<HttpResponseMetaData, RetryingHttpRequesterFilter.HttpResponseException> mapper) Selectively map aresponse
to anRetryingHttpRequesterFilter.HttpResponseException
that can match a retry behaviour throughretryResponses(BiFunction)
.retryDelayedRetries
(BiFunction<HttpRequestMetaData, RetryingHttpRequesterFilter.DelayedRetry, RetryingHttpRequesterFilter.BackOffPolicy> mapper) Deprecated.retryDelayedRetryExceptions
(BiFunction<HttpRequestMetaData, DelayedRetryException, RetryingHttpRequesterFilter.BackOffPolicy> mapper) The retrying-filter will evaluate theThrowable
marked withDelayedRetryException
interface and use the provideddelay
as a constant delay on-top of the retry period already defined.retryExpectationFailed
(boolean retryExpectationFailed) RetriesHttpResponseStatus.EXPECTATION_FAILED
response withoutHttpHeaderNames.EXPECT
header.retryIdempotentRequests
(BiFunction<HttpRequestMetaData, IOException, RetryingHttpRequesterFilter.BackOffPolicy> mapper) Retries idempotent requests when applicable.retryOther
(BiFunction<HttpRequestMetaData, Throwable, RetryingHttpRequesterFilter.BackOffPolicy> mapper) Support additional criteria for determining which requests or errors should be retried.retryResponses
(BiFunction<HttpRequestMetaData, RetryingHttpRequesterFilter.HttpResponseException, RetryingHttpRequesterFilter.BackOffPolicy> mapper) The retrying-filter will evaluateRetryingHttpRequesterFilter.HttpResponseException
that resulted from theresponseMapper(Function)
, and support different retry behaviour according to therequest
and theresponse
.retryResponses
(BiFunction<HttpRequestMetaData, RetryingHttpRequesterFilter.HttpResponseException, RetryingHttpRequesterFilter.BackOffPolicy> mapper, boolean returnOriginalResponses) The retrying-filter will evaluateRetryingHttpRequesterFilter.HttpResponseException
that resulted from theresponseMapper(Function)
, and support different retry behaviour according to therequest
and theresponse
.retryRetryableExceptions
(BiFunction<HttpRequestMetaData, RetryableException, RetryingHttpRequesterFilter.BackOffPolicy> mapper) The retrying-filter will evaluate forRetryableException
s in the request flow.waitForLoadBalancer
(boolean waitForLb) By default, automatic retries wait for the associatedLoadBalancer
to beready
before triggering a retry for requests.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
waitForLoadBalancer
By default, automatic retries wait for the associatedLoadBalancer
to beready
before triggering a retry for requests. This behavior may add latency to requests till the time the load balancer is ready instead of failing fast. This method allows controlling that behavior.- Parameters:
waitForLb
- Whether to wait for theLoadBalancer
to be ready before retrying requests.- Returns:
this
.
-
ignoreServiceDiscovererErrors
By default, fail a request if the last signal from the associatedServiceDiscoverer
was an error. This method disables that behavior.- Parameters:
ignoreSdErrors
- ignoreServiceDiscoverer
errors when evaluating a request failure.- Returns:
this
.
-
maxTotalRetries
Set the maximum number of allowed retry operations before giving up, applied as total max across all retry functions (see.retryDelayedRetries(BiFunction)
,retryIdempotentRequests(BiFunction)
,retryRetryableExceptions(BiFunction)
,retryResponses(BiFunction)
,retryOther(BiFunction)
).Maximum total retries guards the LB/SD readiness flow, making sure LB connection issues will also be retried with a limit.
- Parameters:
maxRetries
- Maximum number of allowed retries before giving up- Returns:
this
-
responseMapper
public RetryingHttpRequesterFilter.Builder responseMapper(Function<HttpResponseMetaData, RetryingHttpRequesterFilter.HttpResponseException> mapper) Selectively map aresponse
to anRetryingHttpRequesterFilter.HttpResponseException
that can match a retry behaviour throughretryResponses(BiFunction)
.- Parameters:
mapper
- aFunction
that maps aHttpResponseMetaData
to anRetryingHttpRequesterFilter.HttpResponseException
or returnsnull
if there is no mapping for response meta-data. In the case that the request cannot be retried, theRetryingHttpRequesterFilter.HttpResponseException
will be returned via the error pathway.It's important that this
Function
doesn't block to avoid performance impacts. It's important that thisFunction
doesn't throw exceptions.- Returns:
this
-
retryRetryableExceptions
public RetryingHttpRequesterFilter.Builder retryRetryableExceptions(BiFunction<HttpRequestMetaData, RetryableException, RetryingHttpRequesterFilter.BackOffPolicy> mapper) The retrying-filter will evaluate forRetryableException
s in the request flow.To disable retries you can return
RetryingHttpRequesterFilter.BackOffPolicy.ofNoRetries()
from themapper
.It's important that this
BiFunction
doesn't block to avoid performance impacts. It's important that thisBiFunction
doesn't throw exceptions.- Parameters:
mapper
- The mapper to map theHttpRequestMetaData
and theRetryableException
to aRetryingHttpRequesterFilter.BackOffPolicy
.- Returns:
this
.
-
retryIdempotentRequests
public RetryingHttpRequesterFilter.Builder retryIdempotentRequests(BiFunction<HttpRequestMetaData, IOException, RetryingHttpRequesterFilter.BackOffPolicy> mapper) Retries idempotent requests when applicable.Note: This predicate expects that the retried
requests
have apayload body
that is replayable, i.e. multiple subscribes to the payloadPublisher
observe the same data.Publisher
s that do not emit any data or which are created from in-memory data are typically replayable.To disable retries you can return
RetryingHttpRequesterFilter.BackOffPolicy.ofNoRetries()
from themapper
.It's important that this
BiFunction
doesn't block to avoid performance impacts. It's important that thisBiFunction
doesn't throw exceptions.- Parameters:
mapper
- The mapper to map theHttpRequestMetaData
and theIOException
to aRetryingHttpRequesterFilter.BackOffPolicy
.- Returns:
this
.
-
retryExpectationFailed
RetriesHttpResponseStatus.EXPECTATION_FAILED
response withoutHttpHeaderNames.EXPECT
header.- Parameters:
retryExpectationFailed
- iftrue
, filter will automatically mapHttpResponseStatus.EXPECTATION_FAILED
intoExpectationFailedException
and retry a request withoutHttpHeaderNames.EXPECT
header.- Returns:
this
.- See Also:
-
retryDelayedRetryExceptions
public RetryingHttpRequesterFilter.Builder retryDelayedRetryExceptions(BiFunction<HttpRequestMetaData, DelayedRetryException, RetryingHttpRequesterFilter.BackOffPolicy> mapper) The retrying-filter will evaluate theThrowable
marked withDelayedRetryException
interface and use the provideddelay
as a constant delay on-top of the retry period already defined.In case a max-delay was set in this builder, the
constant-delay
overrides it and takes precedence.To disable retries and proceed evaluating other retry functions you can return,
RetryingHttpRequesterFilter.BackOffPolicy.ofNoRetries()
from the passedmapper
.It's important that this
BiFunction
doesn't block to avoid performance impacts. It's important that thisBiFunction
doesn't throw exceptions.- Parameters:
mapper
- The mapper to map theHttpRequestMetaData
and thedelayed-exception
to aRetryingHttpRequesterFilter.BackOffPolicy
.- Returns:
this
.
-
retryDelayedRetries
@Deprecated public RetryingHttpRequesterFilter.Builder retryDelayedRetries(BiFunction<HttpRequestMetaData, RetryingHttpRequesterFilter.DelayedRetry, RetryingHttpRequesterFilter.BackOffPolicy> mapper) Deprecated.UseretryDelayedRetryExceptions(BiFunction)
instead.The retrying-filter will evaluate theRetryingHttpRequesterFilter.DelayedRetry
marker interface of an exception and use the provideddelay
as a constant delay on-top of the retry period already defined.In case a max-delay was set in this builder, the
constant-delay
overrides it and takes precedence.To disable retries you can return
RetryingHttpRequesterFilter.BackOffPolicy.NO_RETRIES
from themapper
.It's important that this
BiFunction
doesn't block to avoid performance impacts. It's important that thisBiFunction
doesn't throw exceptions.- Parameters:
mapper
- The mapper to map theHttpRequestMetaData
and thedelayed-exception
to aRetryingHttpRequesterFilter.BackOffPolicy
.- Returns:
this
.
-
retryResponses
public RetryingHttpRequesterFilter.Builder retryResponses(BiFunction<HttpRequestMetaData, RetryingHttpRequesterFilter.HttpResponseException, RetryingHttpRequesterFilter.BackOffPolicy> mapper) The retrying-filter will evaluateRetryingHttpRequesterFilter.HttpResponseException
that resulted from theresponseMapper(Function)
, and support different retry behaviour according to therequest
and theresponse
.To disable retries you can return
RetryingHttpRequesterFilter.BackOffPolicy.NO_RETRIES
from themapper
.It's important that this
BiFunction
doesn't block to avoid performance impacts. It's important that thisBiFunction
doesn't throw exceptions.- Parameters:
mapper
- The mapper to map theHttpRequestMetaData
and thedelayed-exception
to aRetryingHttpRequesterFilter.BackOffPolicy
.- Returns:
this
.
-
retryResponses
public RetryingHttpRequesterFilter.Builder retryResponses(BiFunction<HttpRequestMetaData, RetryingHttpRequesterFilter.HttpResponseException, RetryingHttpRequesterFilter.BackOffPolicy> mapper, boolean returnOriginalResponses) The retrying-filter will evaluateRetryingHttpRequesterFilter.HttpResponseException
that resulted from theresponseMapper(Function)
, and support different retry behaviour according to therequest
and theresponse
.To disable retries you can return
RetryingHttpRequesterFilter.BackOffPolicy.NO_RETRIES
from themapper
.It's important that this
BiFunction
doesn't block to avoid performance impacts. It's important that thisBiFunction
doesn't throw exceptions.- Parameters:
mapper
- The mapper to map theHttpRequestMetaData
and thedelayed-exception
to aRetryingHttpRequesterFilter.BackOffPolicy
.returnOriginalResponses
- whether to unwrap the response defined by theRetryingHttpRequesterFilter.HttpResponseException
meta-data in the case that the request is not retried.- Returns:
this
.
-
retryOther
public RetryingHttpRequesterFilter.Builder retryOther(BiFunction<HttpRequestMetaData, Throwable, RetryingHttpRequesterFilter.BackOffPolicy> mapper) Support additional criteria for determining which requests or errors should be retried.To disable retries you can return
RetryingHttpRequesterFilter.BackOffPolicy.NO_RETRIES
from themapper
.It's important that this
BiFunction
doesn't block to avoid performance impacts. It's important that thisBiFunction
doesn't throw exceptions.- Parameters:
mapper
-BiFunction
that checks whether a given combination ofmeta-data
andcause
should be retried, producing aRetryingHttpRequesterFilter.BackOffPolicy
in such cases.- Returns:
this
-
onRequestRetry
public RetryingHttpRequesterFilter.Builder onRequestRetry(RetryingHttpRequesterFilter.RetryCallbacks onRequestRetry) Callback invoked on everyrequest
retry attempt.This can be used to track when
RetryingHttpRequesterFilter.BackOffPolicy
actually decides to retry a request, to updaterequest meta-data
before a retry, or implement logging/metrics. However, it can not be used to influence the retry decision, use other "retry*" functions for that purpose.- Parameters:
onRequestRetry
-RetryingHttpRequesterFilter.RetryCallbacks
to get notified on everyrequest
retry attempt- Returns:
this
-
build
Builds a retryingRetryingHttpRequesterFilter
with this' builders configuration.- Returns:
- A new retrying
RetryingHttpRequesterFilter
-
retryDelayedRetryExceptions(BiFunction)
instead.