Package io.servicetalk.http.netty
Class RetryingHttpRequesterFilter.Builder
java.lang.Object
io.servicetalk.http.netty.RetryingHttpRequesterFilter.Builder
- Enclosing class:
- RetryingHttpRequesterFilter
A builder for
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.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) 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.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
.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. The mapper should returnnull
if no retry is needed or if it cannot be determined that a retry is needed.- 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 returnRetryingHttpRequesterFilter.BackOffPolicy.NO_RETRIES
from themapper
. It's important that thisFunction
doesn't block to avoid performance impacts.- 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 returnRetryingHttpRequesterFilter.BackOffPolicy.NO_RETRIES
from themapper
. It's important that thisFunction
doesn't block to avoid performance impacts.- 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:
-
retryDelayedRetries
public RetryingHttpRequesterFilter.Builder retryDelayedRetries(BiFunction<HttpRequestMetaData, RetryingHttpRequesterFilter.DelayedRetry, RetryingHttpRequesterFilter.BackOffPolicy> mapper) 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, theconstant-delay
overrides it and takes precedence. To disable retries you can returnRetryingHttpRequesterFilter.BackOffPolicy.NO_RETRIES
from themapper
. It's important that thisFunction
doesn't block to avoid performance impacts.- 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 returnRetryingHttpRequesterFilter.BackOffPolicy.NO_RETRIES
from themapper
. It's important that thisFunction
doesn't block to avoid performance impacts.- Parameters:
mapper
- The mapper to map theHttpRequestMetaData
and thedelayed-exception
to aRetryingHttpRequesterFilter.BackOffPolicy
.- 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 returnRetryingHttpRequesterFilter.BackOffPolicy.NO_RETRIES
from themapper
. It's important that thisFunction
doesn't block to avoid performance impacts.- Parameters:
mapper
-BiFunction
that checks whether a given combination ofmeta-data
andcause
should be retried, producing aRetryingHttpRequesterFilter.BackOffPolicy
in such cases.- Returns:
this
-
build
Builds a retryingRetryingHttpRequesterFilter
with this' builders configuration.- Returns:
- A new retrying
RetryingHttpRequesterFilter
-