public abstract class Retry extends Object
Flux
of Retry.RetrySignal
,
for use with Flux.retryWhen(Retry)
and Mono.retryWhen(Retry)
.
Also provides access to configurable built-in strategies via static factory methods:
Users are encouraged to provide either concrete custom Retry
strategies or builders that produce
such concrete Retry
. The RetrySpec
returned by eg. max(long)
is a good inspiration
for a fluent approach that generates a Retry
at each step and uses immutability/copy-on-write to enable
sharing of intermediate steps (that can thus be considered templates).
Modifier and Type | Class and Description |
---|---|
static interface |
Retry.RetrySignal
State for a
Flux.retryWhen(Retry) Flux retry} or Mono retry . |
Modifier and Type | Field and Description |
---|---|
ContextView |
retryContext |
Modifier | Constructor and Description |
---|---|
|
Retry() |
protected |
Retry(ContextView retryContext) |
Modifier and Type | Method and Description |
---|---|
static RetryBackoffSpec |
backoff(long maxAttempts,
Duration minBackoff)
A
RetryBackoffSpec preconfigured for exponential backoff strategy with jitter, given a maximum number of retry attempts
and a minimum Duration for the backoff. |
static RetryBackoffSpec |
fixedDelay(long maxAttempts,
Duration fixedDelay)
A
RetryBackoffSpec preconfigured for fixed delays (min backoff equals max backoff, no jitter), given a maximum number of retry attempts
and the fixed Duration for the backoff. |
static Retry |
from(Function<Flux<Retry.RetrySignal>,? extends Publisher<?>> function)
|
abstract Publisher<?> |
generateCompanion(Flux<Retry.RetrySignal> retrySignals)
The intent of the functional
Retry class is to let users configure how to react to Retry.RetrySignal
by providing the operator with a companion publisher. |
static RetrySpec |
indefinitely()
A
RetrySpec preconfigured for the most simplistic retry strategy: retry immediately and indefinitely
(similar to Flux.retry() ). |
static RetrySpec |
max(long max)
A
RetrySpec preconfigured for a simple strategy with maximum number of retry attempts. |
static RetrySpec |
maxInARow(long maxInARow)
A
RetrySpec preconfigured for a simple strategy with maximum number of retry attempts over
subsequent transient errors. |
ContextView |
retryContext()
Return the user provided context that was set at construction time.
|
static Retry |
withThrowable(Function<Flux<Throwable>,? extends Publisher<?>> function)
|
public final ContextView retryContext
public Retry()
protected Retry(ContextView retryContext)
public abstract Publisher<?> generateCompanion(Flux<Retry.RetrySignal> retrySignals)
Retry
class is to let users configure how to react to Retry.RetrySignal
by providing the operator with a companion publisher. Any onNext
emitted by this publisher will trigger a retry, but if that emission is delayed compared to the original signal then
the attempt is delayed as well. This method generates the companion, out of a Flux
of Retry.RetrySignal
,
which itself can serve as the simplest form of retry companion (indefinitely and immediately retry on any error).retrySignals
- the original Flux
of Retry.RetrySignal
, notifying of each source error that
might result in a retry attempt, with context around the error and current retry cycle.public ContextView retryContext()
Retry.RetrySignal.retryContextView()
.public static RetryBackoffSpec backoff(long maxAttempts, Duration minBackoff)
RetryBackoffSpec
preconfigured for exponential backoff strategy with jitter, given a maximum number of retry attempts
and a minimum Duration
for the backoff.
maxAttempts
- the maximum number of retry attempts to allowminBackoff
- the minimum Duration
for the first backoffRetryBackoffSpec.maxAttempts(long)
,
RetryBackoffSpec.minBackoff(Duration)
public static RetryBackoffSpec fixedDelay(long maxAttempts, Duration fixedDelay)
RetryBackoffSpec
preconfigured for fixed delays (min backoff equals max backoff, no jitter), given a maximum number of retry attempts
and the fixed Duration
for the backoff.
Note that calling RetryBackoffSpec.minBackoff(Duration)
or RetryBackoffSpec.maxBackoff(Duration)
would switch
back to an exponential backoff strategy.
maxAttempts
- the maximum number of retry attempts to allowfixedDelay
- the Duration
of the fixed delaysRetryBackoffSpec.maxAttempts(long)
,
RetryBackoffSpec.minBackoff(Duration)
,
RetryBackoffSpec.maxBackoff(Duration)
public static RetrySpec max(long max)
RetrySpec
preconfigured for a simple strategy with maximum number of retry attempts.
max
- the maximum number of retry attempts to allowRetrySpec.maxAttempts(long)
public static RetrySpec maxInARow(long maxInARow)
RetrySpec
preconfigured for a simple strategy with maximum number of retry attempts over
subsequent transient errors. An Subscriber.onNext(Object)
between
errors resets the counter (see RetrySpec.transientErrors(boolean)
).
maxInARow
- the maximum number of retry attempts to allow in a row, reset by successful onNextRetrySpec.maxAttempts(long)
,
RetrySpec.transientErrors(boolean)
public static RetrySpec indefinitely()
RetrySpec
preconfigured for the most simplistic retry strategy: retry immediately and indefinitely
(similar to Flux.retry()
).public static final Retry from(Function<Flux<Retry.RetrySignal>,? extends Publisher<?>> function)