Retry strategy based on exponential backoffs, with configurable features. Use Retry#backoff(long, Duration)
to obtain a preconfigured instance to start with.
Retry delays are randomized with a user-provided jitter(double) factor between 0.d (no jitter)
and 1.0 (default is 0.5).
Even with the jitter, the effective backoff delay cannot be less than minBackoff(Duration)
nor more than maxBackoff(Duration). The delays and subsequent attempts are executed on the
provided backoff scheduler(Scheduler). Alternatively, Retry#fixedDelay(long, Duration) provides
a strategy where the min and max backoffs are the same and jitters are deactivated.
Only errors that match the filter(Predicate) are retried (by default all),
and the number of attempts can also limited with maxAttempts(long).
When the maximum attempt of retries is reached, a runtime exception is propagated downstream which
can be pinpointed with reactor.. The cause of
the last attempt's failure is attached as said retryExhausted
exception's cause. This can be customized with onRetryExhaustedThrow(BiFunction).
Additionally, to help dealing with bursts of transient errors in a long-lived Flux as if each burst
had its own backoff, one can choose to set transientErrors(boolean) to true.
The comparison to maxAttempts(long) will then be done with the number of subsequent attempts
that failed without an onNext in between.
The RetryBackoffSpec is copy-on-write and as such can be stored as a "template" and further configured
by different components without a risk of modifying the original configuration.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final BiFunction | |
| pack-priv final BiFunction | |
| pack-priv static final BiFunction | |
| public final Supplier | backoffSchedulerSupplier
The configured |
| public final Predicate | errorFilter
The configured |
| public final boolean | isTransientErrors
The configured transient error handling flag. |
| public final double | jitterFactor
The configured jitter factor, as a |
| public final long | maxAttempts
The configured maximum for retry attempts. |
| public final Duration | maxBackoff
The configured maximum backoff |
| public final Duration | minBackoff
The configured minimum backoff |
| pack-priv final BiFunction | |
| pack-priv final Consumer | |
| pack-priv final Consumer |
| Access | Constructor and Description |
|---|---|
| pack-priv | RetryBackoffSpec(ContextView retryContext, long max, Predicate<? super Throwable> aThrowablePredicate, boolean isTransientErrors, Duration minBackoff, Duration maxBackoff, double jitterFactor, Supplier<Scheduler> backoffSchedulerSupplier, Consumer<Retry.
Copy constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public RetryBackoffSpec | doAfterRetry(Consumer<Retry.
the synchronous hook to execute after retry trigger is started doAfterRetryAdd synchronous behavior to be executed after the retry trigger is emitted in the companion publisher. |
| public RetryBackoffSpec | doAfterRetryAsync(Function<Retry.
the asynchronous hook to execute after original retry trigger is emitted doAsyncAfterRetryAdd asynchronous behavior to be executed after the current retry trigger in the companion publisher,
thus delaying the resulting retry trigger with the additional |
| public RetryBackoffSpec | doBeforeRetry(Consumer<Retry.
the synchronous hook to execute before retry trigger is emitted doBeforeRetryAdd synchronous behavior to be executed before the retry trigger is emitted in the companion publisher. |
| public RetryBackoffSpec | doBeforeRetryAsync(Function<Retry.
the asynchronous hook to execute before original retry trigger is emitted doAsyncBeforeRetryAdd asynchronous behavior to be executed before the current retry trigger in the companion publisher,
thus delaying the resulting retry trigger with the additional |
| public RetryBackoffSpec | |
| public Flux | generateCompanion(Flux<Retry.
the errors from the outer publisher as tRetrySignal objects,
containing the Throwable causing the error as well as retry counter metadata.Implements abstract reactor. RetrySignal emissions, effectively
deciding when to retry.
|
| public RetryBackoffSpec | jitter(double
the new jitter factor as a jitterFactor)double between 0d and 1dSet a jitter factor for exponential backoffs that adds randomness to each backoff. |
| public RetryBackoffSpec | maxAttempts(long
the new retry attempt limit maxAttempts)Set the maximum number of retry attempts allowed. |
| public RetryBackoffSpec | maxBackoff(Duration
the maximum backoff maxBackoff)DurationSet a hard maximum |
| public RetryBackoffSpec | minBackoff(Duration
the minimum backoff minBackoff)DurationSet the minimum |
| public RetryBackoffSpec | |
| public RetryBackoffSpec | Returns: a new copy of theRetryBackoffSpec which can either be further
configured or used as reactor.Set the generator for the |
| public RetryBackoffSpec | |
| public RetryBackoffSpec | transientErrors(boolean
true to activate transient modeSet the transient error mode, indicating that the strategy being built should use
|
| protected void | |
| public RetryBackoffSpec | withRetryContext(ContextView
a new snapshot of user provided data retryContext)Set the user provided |
| asyncPostRetry | back to summary |
|---|---|
| pack-priv final BiFunction<Retry. | |
| asyncPreRetry | back to summary |
|---|---|
| pack-priv final BiFunction<Retry. | |
| BACKOFF_EXCEPTION_GENERATOR | back to summary |
|---|---|
| pack-priv static final BiFunction<RetryBackoffSpec, Retry. | |
| backoffSchedulerSupplier | back to summary |
|---|---|
| public final Supplier<Scheduler> backoffSchedulerSupplier The configured
| |
| errorFilter | back to summary |
|---|---|
| public final Predicate<Throwable> errorFilter The configured
| |
| isTransientErrors | back to summary |
|---|---|
| public final boolean isTransientErrors The configured transient error handling flag.
| |
| jitterFactor | back to summary |
|---|---|
| public final double jitterFactor The configured jitter factor, as a
| |
| maxAttempts | back to summary |
|---|---|
| public final long maxAttempts The configured maximum for retry attempts.
| |
| maxBackoff | back to summary |
|---|---|
| public final Duration maxBackoff The configured maximum backoff
| |
| minBackoff | back to summary |
|---|---|
| public final Duration minBackoff The configured minimum backoff
| |
| retryExhaustedGenerator | back to summary |
|---|---|
| pack-priv final BiFunction<RetryBackoffSpec, Retry. | |
| syncPostRetry | back to summary |
|---|---|
| pack-priv final Consumer<Retry. | |
| syncPreRetry | back to summary |
|---|---|
| pack-priv final Consumer<Retry. | |
| RetryBackoffSpec | back to summary |
|---|---|
| pack-priv RetryBackoffSpec(ContextView retryContext, long max, Predicate<? super Throwable> aThrowablePredicate, boolean isTransientErrors, Duration minBackoff, Duration maxBackoff, double jitterFactor, Supplier<Scheduler> backoffSchedulerSupplier, Consumer<Retry. Copy constructor. | |
| doAfterRetry | back to summary |
|---|---|
| public RetryBackoffSpec doAfterRetry(Consumer<Retry. Add synchronous behavior to be executed after the retry trigger is emitted in the companion publisher. This should not be blocking, as the companion publisher might be publishing events in a shared thread.
| |
| doAfterRetryAsync | back to summary |
|---|---|
| public RetryBackoffSpec doAfterRetryAsync(Function<Retry. Add asynchronous behavior to be executed after the current retry trigger in the companion publisher,
thus delaying the resulting retry trigger with the additional
| |
| doBeforeRetry | back to summary |
|---|---|
| public RetryBackoffSpec doBeforeRetry(Consumer<Retry. Add synchronous behavior to be executed before the retry trigger is emitted in the companion publisher. This should not be blocking, as the companion publisher might be executing in a shared thread.
| |
| doBeforeRetryAsync | back to summary |
|---|---|
| public RetryBackoffSpec doBeforeRetryAsync(Function<Retry. Add asynchronous behavior to be executed before the current retry trigger in the companion publisher,
thus delaying the resulting retry trigger with the additional
| |
| filter | back to summary |
|---|---|
| public RetryBackoffSpec filter(Predicate<? super Throwable> errorFilter) Set the
| |
| generateCompanion | back to summary |
|---|---|
| public Flux Implements abstract reactor. Doc from reactor. Generates the companion publisher responsible for reacting to incoming
When the source signals an error, that The response to that request decides if a retry should be made. Thus, the outer publisher will wait until a signal is emitted by the companion publisher, making it possible to delay retry attempts.
Any
As an example, the simplest form of retry companion would be to return the incoming
| |
| jitter | back to summary |
|---|---|
| public RetryBackoffSpec jitter(double jitterFactor) Set a jitter factor for exponential backoffs that adds randomness to each backoff. This can
be helpful in reducing cascading failure due to retry-storms. This method switches to an
exponential backoff strategy with a zero minimum backoff if not already a backoff strategy.
Defaults to
| |
| maxAttempts | back to summary |
|---|---|
| public RetryBackoffSpec maxAttempts(long maxAttempts) Set the maximum number of retry attempts allowed. 1 meaning "1 retry attempt": the original subscription plus an extra re-subscription in case of an error, but no more.
| |
| maxBackoff | back to summary |
|---|---|
| public RetryBackoffSpec maxBackoff(Duration maxBackoff) Set a hard maximum
| |
| minBackoff | back to summary |
|---|---|
| public RetryBackoffSpec minBackoff(Duration minBackoff) Set the minimum
| |
| modifyErrorFilter | back to summary |
|---|---|
| public RetryBackoffSpec modifyErrorFilter(Function<Predicate<Throwable>, Predicate<? super Throwable>> predicateAdjuster) Allows to augment a previously For example:
| |
| onRetryExhaustedThrow | back to summary |
|---|---|
| public RetryBackoffSpec onRetryExhaustedThrow(BiFunction<RetryBackoffSpec, Retry. Set the generator for the
| |
| scheduler | back to summary |
|---|---|
| public RetryBackoffSpec scheduler(Scheduler backoffScheduler) Set a
| |
| transientErrors | back to summary |
|---|---|
| public RetryBackoffSpec transientErrors(boolean isTransientErrors) Set the transient error mode, indicating that the strategy being built should use
For a backoff based retry, the backoff is also computed based on the index within
the burst, meaning the next error after a recovery will be retried with a
| |
| validateArguments | back to summary |
|---|---|
| protected void validateArguments() | |
| withRetryContext | back to summary |
|---|---|
| public RetryBackoffSpec withRetryContext(ContextView retryContext) Set the user provided
| |