Class Retry
- Direct Known Subclasses:
RetryBackoffSpec,RetrySpec
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 e.g. 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).
- Author:
- Simon Baslé
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceState used inFlux.retryWhen(Retry)andMono.retryWhen(Retry), providing theThrowablethat caused the source to fail as well as counters keeping track of retries. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RetryBackoffSpecARetryBackoffSpecpreconfigured for exponential backoff strategy with jitter, given a maximum number of retry attempts and a minimumDurationfor the backoff.static RetryBackoffSpecfixedDelay(long maxAttempts, Duration fixedDelay) ARetryBackoffSpecpreconfigured for fixed delays (min backoff equals max backoff, no jitter), given a maximum number of retry attempts and the fixedDurationfor the backoff.static final Retryfrom(Function<Flux<Retry.RetrySignal>, ? extends Publisher<?>> function) abstract Publisher<?>generateCompanion(Flux<Retry.RetrySignal> retrySignals) Generates the companion publisher responsible for reacting to incomingRetry.RetrySignalemissions, effectively deciding when to retry.static RetrySpecARetrySpecpreconfigured for the most simplistic retry strategy: retry immediately and indefinitely (similar toFlux.retry()).static RetrySpecmax(long max) ARetrySpecpreconfigured for a simple strategy with maximum number of retry attempts.static RetrySpecmaxInARow(long maxInARow) ARetrySpecpreconfigured for a simple strategy with maximum number of retry attempts over subsequent transient errors.Return the user provided context that was set at construction time.static final RetrywithThrowable(Function<Flux<Throwable>, ? extends Publisher<?>> function)
-
Field Details
-
retryContext
-
-
Constructor Details
-
Retry
public Retry() -
Retry
-
-
Method Details
-
generateCompanion
Generates the companion publisher responsible for reacting to incomingRetry.RetrySignalemissions, effectively deciding when to retry.When the source signals an error, that
onErrorsignal will be suppressed. ItsThrowablewill instead be attached to aRetry.RetrySignal, immediately emitted on theretrySignalspublisher. Right after that emission,request(1)is called on the companion publisher.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
onNextemitted by the companion publisher triggers a retry,onErrorwill fail the outer publisher andonCompletewill complete the outer publisher (effectively suppressing the original error/Throwable).As an example, the simplest form of retry companion would be to return the incoming
FluxofRetry.RetrySignalwithout modification. This would render a retry strategy that immediately retries, forever.- Parameters:
retrySignals- the errors from the outer publisher asRetry.RetrySignalobjects, containing theThrowablecausing the error as well as retry counter metadata.- Returns:
- the companion publisher responsible for reacting to incoming
Retry.RetrySignalemissions, effectively deciding when to retry.
-
retryContext
Return the user provided context that was set at construction time.- Returns:
- the user provided context that will be accessible via
Retry.RetrySignal.retryContextView().
-
backoff
ARetryBackoffSpecpreconfigured for exponential backoff strategy with jitter, given a maximum number of retry attempts and a minimumDurationfor the backoff.- Parameters:
maxAttempts- the maximum number of retry attempts to allowminBackoff- the minimumDurationfor the first backoff- Returns:
- the exponential backoff spec for further configuration
- See Also:
-
fixedDelay
ARetryBackoffSpecpreconfigured for fixed delays (min backoff equals max backoff, no jitter), given a maximum number of retry attempts and the fixedDurationfor the backoff.Note that calling
RetryBackoffSpec.minBackoff(Duration)orRetryBackoffSpec.maxBackoff(Duration)would switch back to an exponential backoff strategy.- Parameters:
maxAttempts- the maximum number of retry attempts to allowfixedDelay- theDurationof the fixed delays- Returns:
- the fixed delays spec for further configuration
- See Also:
-
max
ARetrySpecpreconfigured for a simple strategy with maximum number of retry attempts.- Parameters:
max- the maximum number of retry attempts to allow- Returns:
- the max attempt spec for further configuration
- See Also:
-
maxInARow
ARetrySpecpreconfigured for a simple strategy with maximum number of retry attempts over subsequent transient errors. AnSubscriber.onNext(Object)between errors resets the counter (seeRetrySpec.transientErrors(boolean)).- Parameters:
maxInARow- the maximum number of retry attempts to allow in a row, reset by successful onNext- Returns:
- the max in a row spec for further configuration
- See Also:
-
indefinitely
ARetrySpecpreconfigured for the most simplistic retry strategy: retry immediately and indefinitely (similar toFlux.retry()).- Returns:
- the retry indefinitely spec for further configuration
-
from
-
withThrowable
-