Interface Retry<T>
- Type Parameters:
T
- Application context type
- All Known Implementing Classes:
DefaultRetry
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);
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Retry
<T> 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> 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 retryingFlux
based on the properties configured for this function.Deprecated.Returns a retry function with backoff delay.doOnRetry
(Consumer<? super RetryContext<T>> onRetry) Deprecated.Returns a retry function that invokes the provided onRetry callback before every retry.exponentialBackoff
(Duration firstBackoff, Duration maxBackoff) Deprecated.Returns a retry function with exponential backoff delay.exponentialBackoffWithJitter
(Duration firstBackoff, Duration maxBackoff) Deprecated.Returns a retry function with full jitter backoff strategy.fixedBackoff
(Duration backoffInterval) Deprecated.Returns a retry function with fixed backoff delay.Deprecated.Returns a retry function that applies jitter to the backoff delay.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.randomBackoff
(Duration firstBackoff, Duration maxBackoff) Deprecated.Returns a retry function with random de-correlated jitter backoff strategy.retryMax
(long maxRetries) Deprecated.Retry function that retries n times.Deprecated.Retry function that retries once.Deprecated.Returns a retry function with timeout.default Retry
Deprecated.Converts this retry function to a reactor retry function for compatibility.withApplicationContext
(T applicationContext) Deprecated.Returns a retry function with an application context that may be used to perform any rollbacks before a retry.withBackoffScheduler
(Scheduler scheduler) Deprecated.Returns a retry function that uses the scheduler provided for backoff delays.
-
Method Details
-
any
Deprecated.Returns a retry function that retries any exception, once. More constraints may be added usingretryMax(long)
ortimeout(Duration)
.- Returns:
- retry function that retries on any exception
-
anyOf
Deprecated.Returns a retry function that retries errors resulting from any of the specified exceptions, once. More constraints may be added usingretryMax(long)
ortimeout(Duration)
.- Parameters:
retriableExceptions
- Exceptions that may be retried- Returns:
- retry function that retries indefinitely, only for specified exceptions
-
allBut
Deprecated.Returns a retry function that retries errors resulting from all exceptions except the specified non-retriable exceptions, once. More constraints may be added usingretryMax(long)
ortimeout(Duration)
.- Parameters:
nonRetriableExceptions
- exceptions that may not be retried- Returns:
- retry function that retries all exceptions except the specified non-retriable exceptions.
-
onlyIf
Deprecated.Retry function that retries only if the predicate returns true, with no limit to the number of attempts.- Parameters:
predicate
- Predicate that determines if next retry is performed- Returns:
- Retry function with predicate
-
withApplicationContext
Deprecated.Returns a retry function with an application context that may be used to perform any rollbacks before a retry. This application context is provided to any retry predicateonlyIf(Predicate)
, custom backoff functionbackoff(Backoff)
and retry callbackdoOnRetry(Consumer)
. All other properties of this retry function are retained in the returned instance.- Parameters:
applicationContext
- Application context- Returns:
- retry function with associated application context
-
doOnRetry
Deprecated.Returns a retry function that invokes the provided onRetry callback before every retry. TheRetryContext
provided to the callback contains the iteration and the any application context set usingwithApplicationContext(Object)
. All other properties of this retry function are retained in the returned instance.- Parameters:
onRetry
- callback to invoke before retries- Returns:
- retry function with callback
-
retryOnce
Deprecated.Retry function that retries once.- Returns:
- Retry function for one retry
-
retryMax
Deprecated.Retry function that retries n times.- Parameters:
maxRetries
- number of retries- Returns:
- Retry function for n retries
-
timeout
Deprecated.Returns a retry function with timeout. The timeout starts from the instant that this function is applied, and the function keeps retrying until the timeout expires (or until the configured maximum number of attempts, if it has been set). All other properties of this retry function are retained in the returned instance.- Parameters:
timeout
- timeout after which no new retries are initiated- Returns:
- retry function with global timeout
-
backoff
Deprecated.Returns a retry function with backoff delay. All other properties of this retry function are retained in the returned instance.- Parameters:
backoff
- the backoff function to determine backoff delay- Returns:
- retry function with backoff
-
jitter
Deprecated.Returns a retry function that applies jitter to the backoff delay. All other properties of this retry function are retained in the returned instance.- Parameters:
jitter
- Jitter function to randomize backoff delay- Returns:
- retry function with jitter for backoff
-
withBackoffScheduler
Deprecated.Returns a retry function that uses the scheduler provided for backoff delays. All other properties of this retry function are retained in the returned instance.- Parameters:
scheduler
- the scheduler for backoff delays- Returns:
- retry function with backoff scheduler
-
noBackoff
Deprecated.Returns a retry function with no backoff delay. This is the default. All other properties of this retry function are retained in the returned instance.- Returns:
- retry function with no backoff delay
-
fixedBackoff
Deprecated.Returns a retry function with fixed backoff delay. All other properties of this retry function are retained in the returned instance.- Parameters:
backoffInterval
- fixed backoff delay applied before every retry- Returns:
- retry function with fixed backoff delay
-
exponentialBackoff
Deprecated.Returns a retry function with exponential backoff delay. All other properties of this retry function are retained in the returned instance.Retries are performed after a backoff interval of
firstBackoff * (2 ** n)
where n is the next iteration number. IfmaxBackoff
is not null, the maximum backoff applied will be limited tomaxBackoff
.- Parameters:
firstBackoff
- the delay for the first backoff, which is also used as the coefficient for subsequent backoffsmaxBackoff
- the maximum backoff delay before a retry- Returns:
- retry function with exponential backoff delay
-
exponentialBackoffWithJitter
Deprecated.Returns a retry function with full jitter backoff strategy. All other properties of this retry function are retained in the returned instance.Retries are performed after a random backoff interval between
firstBackoff
andfirstBackoff * (2 ** n)
where n is the next iteration number. IfmaxBackoff
is not null, the maximum backoff applied will be limited tomaxBackoff
.- Parameters:
firstBackoff
- the delay for the first backoff, which is also used as the coefficient for subsequent backoffsmaxBackoff
- the maximum backoff delay before a retry- Returns:
- retry function with full jitter backoff strategy
-
randomBackoff
Deprecated.Returns a retry function with random de-correlated jitter backoff strategy. All other properties of this retry function are retained in the returned instance.Retries are performed after a backoff interval of
random_between(firstBackoff, prevBackoff * 3)
, with a minimum value offirstBackoff
. IfmaxBackoff
is not null, the maximum backoff applied will be limited tomaxBackoff
.- Parameters:
firstBackoff
- the delay for the first backoff, also used as minimum backoffmaxBackoff
- the maximum backoff delay before a retry- Returns:
- retry function with de-correlated jitter backoff strategy
-
apply
Deprecated.Transforms the source into a retryingFlux
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);
- Parameters:
source
- the source publisher- Returns:
Flux
with the retry properties of this retry function
-
toReactorRetry
Deprecated.Converts this retry function to a reactor retry function for compatibility.- Returns:
- a converted retry function.
-
RetrySpec
andRetryBackoffSpec
instead.