Class RetryInterceptor
java.lang.Object
com.github.mizosoft.methanol.RetryInterceptor
- All Implemented Interfaces:
Methanol.Interceptor
An interceptor that retries HTTP requests based on configurable conditions.
Retry conditions are evaluated in the order they are added. The first matching condition determines the next request to send. Later conditions are not evaluated.
Example:
Retry server errors with exponential backoff:var client = Methanol.newBuilder()
.interceptor(RetryInterceptor.newBuilder()
.maxRetries(3)
.backoff(BackoffStrategy.exponential(
Duration.ofMillis(100),
Duration.ofSeconds(10)).withJitter())
.onStatus(500, 502, 503, 504)
.onException(ConnectException.class)
.build())
.build();
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA strategy for backing off (delaying) before a retry.static final classA builder ofRetryInterceptorinstances.static interfaceContext for deciding whether an HTTP call should be retried.static interfaceA listener forRetryInterceptorevents.Nested classes/interfaces inherited from interface Methanol.Interceptor
Methanol.Interceptor.Chain<T> -
Method Summary
Modifier and TypeMethodDescription<T> HttpResponse<T> intercept(HttpRequest request, Methanol.Interceptor.Chain<T> chain) Intercepts given request and returns the resulting response, usually by forwarding to the given chain.<T> CompletableFuture<HttpResponse<T>> interceptAsync(HttpRequest request, Methanol.Interceptor.Chain<T> chain) Intercepts the given request and returns aCompletableFuturefor the resulting response, usually by forwarding to the given chain.static RetryInterceptor.BuilderReturns a new builder ofRetryInterceptorinstances.
-
Method Details
-
intercept
public <T> HttpResponse<T> intercept(HttpRequest request, Methanol.Interceptor.Chain<T> chain) throws IOException, InterruptedException Description copied from interface:Methanol.InterceptorIntercepts given request and returns the resulting response, usually by forwarding to the given chain.- Specified by:
interceptin interfaceMethanol.Interceptor- Throws:
IOExceptionInterruptedException
-
interceptAsync
public <T> CompletableFuture<HttpResponse<T>> interceptAsync(HttpRequest request, Methanol.Interceptor.Chain<T> chain) Description copied from interface:Methanol.InterceptorIntercepts the given request and returns aCompletableFuturefor the resulting response, usually by forwarding to the given chain.- Specified by:
interceptAsyncin interfaceMethanol.Interceptor
-
newBuilder
Returns a new builder ofRetryInterceptorinstances.
-