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 classAServiceRejectionPolicybuilder to support a custom policy. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ServiceRejectionPolicyDefault response rejection policy.static final CharSequenceCustom 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 aHttpResponseMetaDatabased on theCircuitBreakerthat matched theHttpRequestMetaData.retryAfterMillisHint(Duration duration) A hard-coded delay in milliseconds to be supplied as a Retry-After-Millis HTTP header in aHttpResponseMetaData.Pre-definedresponsethat signalsHttpResponseStatus.SERVICE_UNAVAILABLEto the peer.Pre-definedresponsethat signalsHttpResponseStatus.TOO_MANY_REQUESTSto 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
HttpResponseMetaDataconsumer, 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 aHttpResponseMetaDatabased on theCircuitBreakerthat matched theHttpRequestMetaData.- Returns:
- A
HttpResponseMetaDataconsumer, that enhances the headers with a Retry-After figure in seconds based on the duration the matchingCircuitBreakerwill 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
HttpResponseMetaDataconsumer, that enhances the headers with a fixed Retry-After-Millis figure in milliseconds.
-
tooManyRequests
public static BiFunction<HttpRequestMetaData,StreamingHttpResponseFactory, tooManyRequests()Single<StreamingHttpResponse>> Pre-definedresponsethat signalsHttpResponseStatus.TOO_MANY_REQUESTSto the peer.- Returns:
- A
BiFunctionthat regardless the input, it will always return atoo-many-requestsresponse.
-