Class ServiceRejectionPolicy
java.lang.Object
io.servicetalk.traffic.resilience.http.ServiceRejectionPolicy
Rejection Policy to rule the behavior of service rejections due to capacity or open circuit.
This is meant to be used as a policy on the
TrafficResilienceHttpServiceFilter
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
AServiceRejectionPolicy
builder to support a custom policy. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ServiceRejectionPolicy
Default response rejection policy.static final CharSequence
Custom retry-after header that supports milliseconds resolution, rather than seconds. -
Method Summary
Modifier and TypeMethodDescriptionstatic Consumer<HttpResponseMetaData>
retryAfterHint
(int seconds) A hard-coded delay in seconds to be supplied as a Retry-After HTTP header in aHttpResponseMetaData
.A delay in seconds to be supplied as a Retry-After HTTP header in aHttpResponseMetaData
based on theCircuitBreaker
that matched theHttpRequestMetaData
.retryAfterMillisHint
(Duration duration) A hard-coded delay in milliseconds to be supplied as a Retry-After-Millis HTTP header in aHttpResponseMetaData
.Pre-definedresponse
that signalsHttpResponseStatus.SERVICE_UNAVAILABLE
to the peer.Pre-definedresponse
that signalsHttpResponseStatus.TOO_MANY_REQUESTS
to the peer.
-
Field Details
-
RETRY_AFTER_MILLIS
Custom retry-after header that supports milliseconds resolution, rather than seconds. -
DEFAULT_REJECTION_POLICY
Default response rejection policy.- When a request is rejected due to capacity, the service will respond
tooManyRequests()
. - When a request is rejected due to capacity, the service will NOT include a retry-after header.
- When a request is rejected due to breaker, the service will respond
serviceUnavailable()
. - When a request is rejected due to breaker, the service will respond with Retry-After header hinting the duration the breaker will remain open.
- When a request is rejected due to capacity, the service will respond
-
-
Method Details
-
retryAfterHint
A hard-coded delay in seconds to be supplied as a Retry-After HTTP header in aHttpResponseMetaData
.- Parameters:
seconds
- The value (in seconds) to be used in the Retry-After header.- Returns:
- A
HttpResponseMetaData
consumer, that enhances the headers with a fixed Retry-After figure in seconds.
-
retryAfterHintOfBreaker
A delay in seconds to be supplied as a Retry-After HTTP header in aHttpResponseMetaData
based on theCircuitBreaker
that matched theHttpRequestMetaData
.- Returns:
- A
HttpResponseMetaData
consumer, that enhances the headers with a Retry-After figure in seconds based on the duration the matchingCircuitBreaker
will remain open, or a fallback period.
-
retryAfterMillisHint
public static BiConsumer<HttpResponseMetaData,CircuitBreaker> retryAfterMillisHint(Duration duration) A hard-coded delay in milliseconds to be supplied as a Retry-After-Millis HTTP header in aHttpResponseMetaData
. Being a custom Http header, it will require special handling on the peer side.- Parameters:
duration
- The duration to be used in the Retry-After-Millis header.- Returns:
- A
HttpResponseMetaData
consumer, that enhances the headers with a fixed Retry-After-Millis figure in milliseconds.
-
tooManyRequests
public static BiFunction<HttpRequestMetaData,StreamingHttpResponseFactory, tooManyRequests()Single<StreamingHttpResponse>> Pre-definedresponse
that signalsHttpResponseStatus.TOO_MANY_REQUESTS
to the peer.- Returns:
- A
BiFunction
that regardless the input, it will always return atoo-many-requests
response.
-