T
- Application context typeRetrySpec
and RetryBackoffSpec
instead.@Deprecated public interface Retry<T> extends Function<Flux<Throwable>,org.reactivestreams.Publisher<Long>>
Flux.retryWhen(reactor.util.retry.Retry)
and Mono.retryWhen(reactor.util.retry.Retry)
, after conversion via Retry.withThrowable(Function)
.
Each change in configuration returns a new instance (copy configuration), which
makes Retry
suitable for creating configuration templates that can be fine
tuned for specific cases without impacting the original general use-case configuration.
Example usage:
retry = Retry.anyOf(IOException.class)
.randomBackoff(Duration.ofMillis(100), Duration.ofSeconds(60))
.withApplicationContext(appContext)
.doOnRetry(context -> context.applicationContext().rollback());
flux.retryWhen(retry);
Modifier and Type | Method and Description |
---|---|
static <T> Retry<T> |
allBut(Class<? extends Throwable>... nonRetriableExceptions)
Deprecated.
Returns a retry function that retries errors resulting from all exceptions except
the specified non-retriable exceptions, once.
|
static <T> Retry<T> |
any()
Deprecated.
Returns a retry function that retries any exception, once.
|
static <T> Retry<T> |
anyOf(Class<? extends Throwable>... retriableExceptions)
Deprecated.
Returns a retry function that retries errors resulting from any of the
specified exceptions, once.
|
default <S> Flux<S> |
apply(org.reactivestreams.Publisher<S> source)
Deprecated.
Transforms the source into a retrying
Flux based on the properties
configured for this function. |
Retry<T> |
backoff(Backoff backoff)
Deprecated.
Returns a retry function with backoff delay.
|
Retry<T> |
doOnRetry(Consumer<? super RetryContext<T>> onRetry)
Deprecated.
Returns a retry function that invokes the provided onRetry
callback before every retry.
|
default Retry<T> |
exponentialBackoff(Duration firstBackoff,
Duration maxBackoff)
Deprecated.
Returns a retry function with exponential backoff delay.
|
default Retry<T> |
exponentialBackoffWithJitter(Duration firstBackoff,
Duration maxBackoff)
Deprecated.
Returns a retry function with full jitter backoff strategy.
|
default Retry<T> |
fixedBackoff(Duration backoffInterval)
Deprecated.
Returns a retry function with fixed backoff delay.
|
Retry<T> |
jitter(Jitter jitter)
Deprecated.
Returns a retry function that applies jitter to the backoff delay.
|
default Retry<T> |
noBackoff()
Deprecated.
Returns a retry function with no backoff delay.
|
static <T> Retry<T> |
onlyIf(Predicate<? super RetryContext<T>> predicate)
Deprecated.
Retry function that retries only if the predicate returns true, with no limit to
the number of attempts.
|
default Retry<T> |
randomBackoff(Duration firstBackoff,
Duration maxBackoff)
Deprecated.
Returns a retry function with random de-correlated jitter backoff strategy.
|
Retry<T> |
retryMax(long maxRetries)
Deprecated.
Retry function that retries n times.
|
default Retry<T> |
retryOnce()
Deprecated.
Retry function that retries once.
|
Retry<T> |
timeout(Duration timeout)
Deprecated.
Returns a retry function with timeout.
|
Retry<T> |
withApplicationContext(T applicationContext)
Deprecated.
Returns a retry function with an application context that may be
used to perform any rollbacks before a retry.
|
Retry<T> |
withBackoffScheduler(Scheduler scheduler)
Deprecated.
Returns a retry function that uses the scheduler provided for
backoff delays.
|
static <T> Retry<T> any()
retryMax(long)
or timeout(Duration)
.@SafeVarargs static <T> Retry<T> anyOf(Class<? extends Throwable>... retriableExceptions)
retryMax(long)
or timeout(Duration)
.retriableExceptions
- Exceptions that may be retried@SafeVarargs static <T> Retry<T> allBut(Class<? extends Throwable>... nonRetriableExceptions)
retryMax(long)
or timeout(Duration)
.nonRetriableExceptions
- exceptions that may not be retriedstatic <T> Retry<T> onlyIf(Predicate<? super RetryContext<T>> predicate)
predicate
- Predicate that determines if next retry is performedRetry<T> withApplicationContext(T applicationContext)
onlyIf(Predicate)
,
custom backoff function backoff(Backoff)
and retry
callback doOnRetry(Consumer)
. All other properties of
this retry function are retained in the returned instance.applicationContext
- Application contextRetry<T> doOnRetry(Consumer<? super RetryContext<T>> onRetry)
RetryContext
provided
to the callback contains the iteration and the any application
context set using withApplicationContext(Object)
.
All other properties of this retry function are retained in the
returned instance.onRetry
- callback to invoke before retriesdefault Retry<T> retryOnce()
Retry<T> retryMax(long maxRetries)
maxRetries
- number of retriesRetry<T> timeout(Duration timeout)
timeout
- timeout after which no new retries are initiatedRetry<T> backoff(Backoff backoff)
backoff
- the backoff function to determine backoff delayRetry<T> jitter(Jitter jitter)
jitter
- Jitter function to randomize backoff delayRetry<T> withBackoffScheduler(Scheduler scheduler)
scheduler
- the scheduler for backoff delaysdefault Retry<T> noBackoff()
default Retry<T> fixedBackoff(Duration backoffInterval)
backoffInterval
- fixed backoff delay applied before every retrydefault Retry<T> exponentialBackoff(Duration firstBackoff, Duration maxBackoff)
Retries are performed after a backoff interval of firstBackoff * (2 ** n)
where n is the next iteration number. If maxBackoff
is not null, the maximum
backoff applied will be limited to maxBackoff
.
firstBackoff
- the delay for the first backoff, which is also used as the coefficient for subsequent backoffsmaxBackoff
- the maximum backoff delay before a retrydefault Retry<T> exponentialBackoffWithJitter(Duration firstBackoff, Duration maxBackoff)
Retries are performed after a random backoff interval between firstBackoff
and
firstBackoff * (2 ** n)
where n is the next iteration number. If maxBackoff
is not null, the maximum backoff applied will be limited to maxBackoff
.
firstBackoff
- the delay for the first backoff, which is also used as the coefficient for subsequent backoffsmaxBackoff
- the maximum backoff delay before a retrydefault Retry<T> randomBackoff(Duration firstBackoff, Duration maxBackoff)
Retries are performed after a backoff interval of random_between(firstBackoff, prevBackoff * 3)
,
with a minimum value of firstBackoff
. If maxBackoff
is not null, the maximum backoff applied will be limited to maxBackoff
.
firstBackoff
- the delay for the first backoff, also used as minimum backoffmaxBackoff
- the maximum backoff delay before a retrydefault <S> Flux<S> apply(org.reactivestreams.Publisher<S> source)
Flux
based on the properties
configured for this function.
Example usage:
retry = Retry.anyOf(IOException.class)
.withApplicationContext(appContext)
.doOnRetry(context -> context.applicationContext().rollback())
.exponentialBackoff(Duration.ofMillis(100), Duration.ofSeconds(60));
flux.as(retry);
source
- the source publisherFlux
with the retry properties of this retry function