Retry strategy with configurable features. Use Retry#max(long),
Retry#maxInARow(long) or Retry#indefinitely() to obtain a preconfigured instance to start with.
Only errors that match the filter(Predicate) are retried (by default all), up to maxAttempts(long) times.
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 attempt counter, 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 RetrySpec 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 final Consumer | |
| pack-priv final Consumer | |
| public final Predicate | errorFilter
The configured |
| public final boolean | isTransientErrors
The configured transient error handling flag. |
| pack-priv static final Duration | |
| public final long | maxAttempts
The configured maximum for retry attempts. |
| pack-priv static final BiFunction | |
| pack-priv static final Consumer | |
| pack-priv static final BiFunction | |
| pack-priv final BiFunction |
| Access | Constructor and Description |
|---|---|
| pack-priv | RetrySpec(ContextView retryContext, long max, Predicate<? super Throwable> aThrowablePredicate, boolean isTransientErrors, Consumer<Retry.
Copy constructor. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static <T> Mono | applyHooks(Retry.
|
| public RetrySpec | 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 RetrySpec | 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 RetrySpec | 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 RetrySpec | 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 RetrySpec | |
| public Flux | generateCompanion(Flux<Retry.
the errors from the outer publisher as fluxRetrySignal objects,
containing the Throwable causing the error as well as retry counter metadata.Implements abstract reactor. RetrySignal emissions, effectively
deciding when to retry.
|
| public RetrySpec | maxAttempts(long
the new retry attempt limit maxAttempts)Set the maximum number of retry attempts allowed. |
| public RetrySpec | |
| public RetrySpec | onRetryExhaustedThrow(BiFunction<RetrySpec, Retry.
Set the generator for the |
| public RetrySpec | transientErrors(boolean
true to activate transient modeSet the transient error mode, indicating that the strategy being built should use
|
| public RetrySpec | 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. | |
| doPostRetry | back to summary |
|---|---|
| pack-priv final Consumer<Retry. | |
| doPreRetry | back to summary |
|---|---|
| pack-priv final Consumer<Retry. | |
| 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.
| |
| MAX_BACKOFF | back to summary |
|---|---|
| pack-priv static final Duration MAX_BACKOFF | |
| maxAttempts | back to summary |
|---|---|
| public final long maxAttempts The configured maximum for retry attempts.
| |
| NO_OP_BIFUNCTION | back to summary |
|---|---|
| pack-priv static final BiFunction<Retry. | |
| NO_OP_CONSUMER | back to summary |
|---|---|
| pack-priv static final Consumer<Retry. | |
| RETRY_EXCEPTION_GENERATOR | back to summary |
|---|---|
| pack-priv static final BiFunction<RetrySpec, Retry. | |
| retryExhaustedGenerator | back to summary |
|---|---|
| pack-priv final BiFunction<RetrySpec, Retry. | |
| RetrySpec | back to summary |
|---|---|
| pack-priv RetrySpec(ContextView retryContext, long max, Predicate<? super Throwable> aThrowablePredicate, boolean isTransientErrors, Consumer<Retry. Copy constructor. | |
| applyHooks | back to summary |
|---|---|
| pack-priv static <T> Mono | |
| doAfterRetry | back to summary |
|---|---|
| public RetrySpec 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 RetrySpec 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 RetrySpec 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 RetrySpec 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 RetrySpec 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
| |
| maxAttempts | back to summary |
|---|---|
| public RetrySpec 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. | |
| modifyErrorFilter | back to summary |
|---|---|
| public RetrySpec modifyErrorFilter(Function<Predicate<Throwable>, Predicate<? super Throwable>> predicateAdjuster) Allows to augment a previously For example:
| |
| onRetryExhaustedThrow | back to summary |
|---|---|
| public RetrySpec onRetryExhaustedThrow(BiFunction<RetrySpec, Retry. Set the generator for the
| |
| transientErrors | back to summary |
|---|---|
| public RetrySpec transientErrors(boolean isTransientErrors) Set the transient error mode, indicating that the strategy being built should use
In the case of a simple count-based retry, this means that the | |
| withRetryContext | back to summary |
|---|---|
| public RetrySpec withRetryContext(ContextView retryContext) Set the user provided
| |