Package io.smallrye.mutiny.groups
Class UniRetry<T>
- java.lang.Object
-
- io.smallrye.mutiny.groups.UniRetry<T>
-
public class UniRetry<T> extends java.lang.Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Uni<T>atMost(long numberOfAttempts)Uni<T>expireAt(long expireAt)Uni<T>expireIn(long expireIn)Uni<T>indefinitely()Uni<T>until(java.util.function.Predicate<? super java.lang.Throwable> predicate)Uni<T>when(java.util.function.Function<Multi<java.lang.Throwable>,? extends org.reactivestreams.Publisher<?>> whenStreamFactory)UniRetry<T>withBackOff(java.time.Duration initialBackOff)Configures a back-off delay between to attempt to re-subscribe.UniRetry<T>withBackOff(java.time.Duration initialBackOff, java.time.Duration maxBackOff)Configures a back-off delay between to attempt to re-subscribe.UniRetry<T>withJitter(double jitter)Configures the random factor when using back-off.
-
-
-
Method Detail
-
indefinitely
public Uni<T> indefinitely()
Produces aUniresubscribing to the currentUniuntil it gets an item (potentiallynull) On every failure, it re-subscribes, indefinitely.- Returns:
- the
Uni
-
atMost
public Uni<T> atMost(long numberOfAttempts)
Produces aUniresubscribing to the currentUniat mostnumberOfAttemptstime, until it gets an item (potentiallynull). On every failure, it re-subscribes.If the number of attempt is reached, the last failure is propagated.
- Parameters:
numberOfAttempts- the number of attempt, must be greater than zero- Returns:
- a new
Uniretrying at mostnumberOfAttemptstimes to subscribe to the currentUniuntil it gets an item. When the number of attempt is reached, the last failure is propagated. If the back-off has been configured, a delay is introduced between the attempts.
-
expireAt
public Uni<T> expireAt(long expireAt)
Produces aUniresubscribing to the currentUniuntilexpireAttime or until it gets an item (potentiallynull). On every failure, it re-subscribes.If expiration time is passed, the last failure is propagated. Backoff must be configured.
- Parameters:
expireAt- absolute time in millis that specifies when to give up- Returns:
- a new
Uniretrying to subscribe to the currentUniuntil it gets an item or until expirationexpireAt. When the expiration is reached, the last failure is propagated. - Throws:
java.lang.IllegalArgumentException- if back off not configured,
-
expireIn
public Uni<T> expireIn(long expireIn)
Produces aUniresubscribing to the currentUniuntilexpireIntime or until it gets an item (potentiallynull). On every failure, it re-subscribes.If expiration time is passed, the last failure is propagated. Backoff must be configured.
- Parameters:
expireIn- relative time in millis that specifies when to give up- Returns:
- a new
Uniretrying to subscribe to the currentUniuntil it gets an item or until expirationexpireIn. When the expiration is reached, the last failure is propagated. - Throws:
java.lang.IllegalArgumentException- if back off not configured,
-
until
public Uni<T> until(java.util.function.Predicate<? super java.lang.Throwable> predicate)
Produces aUniresubscribing to the currentUniuntil the given predicate returnsfalse. The predicate is called with the failure emitted by the currentUni.- Parameters:
predicate- the predicate that determines if a re-subscription may happen in case of a specific failure, must not benull. If the predicate returnstruefor the given failure, a re-subscription is attempted.- Returns:
- the new
Uniinstance
-
when
public Uni<T> when(java.util.function.Function<Multi<java.lang.Throwable>,? extends org.reactivestreams.Publisher<?>> whenStreamFactory)
Produces aUniresubscribing to the currentUniwhen thePublisherproduced by the given method emits an item. AsatMost(long), on every failure, it re-subscribes. However, a delay is introduced before re-subscribing. The re-subscription happens when the produced streams emits an item. If this stream fails, the producedUnipropagates a failure. It the streams completes, the producedUnipropagatesnull.
-
withBackOff
public UniRetry<T> withBackOff(java.time.Duration initialBackOff)
Configures a back-off delay between to attempt to re-subscribe. A random factor (jitter) is applied to increase the delay when several failures happen.- Parameters:
initialBackOff- the initial back-off duration, must not benull, must not be negative.- Returns:
- this object to configure the retry policy.
-
withBackOff
public UniRetry<T> withBackOff(java.time.Duration initialBackOff, java.time.Duration maxBackOff)
Configures a back-off delay between to attempt to re-subscribe. A random factor (jitter) is applied to increase he delay when several failures happen. The max delays ismaxBackOff.- Parameters:
initialBackOff- the initial back-off duration, must not benull, must not be negative.maxBackOff- the max back-off duration, must not benull, must not be negative.- Returns:
- this object to configure the retry policy.
-
-