Package io.github.resilience4j.reactor
Class ReactorOperatorFallbackDecorator<T>
java.lang.Object
io.github.resilience4j.reactor.ReactorOperatorFallbackDecorator<T>
- Type Parameters:
T- the value type of the upstream and downstream
- All Implemented Interfaces:
Function<org.reactivestreams.Publisher<T>,,org.reactivestreams.Publisher<T>> UnaryOperator<org.reactivestreams.Publisher<T>>
public class ReactorOperatorFallbackDecorator<T>
extends Object
implements UnaryOperator<org.reactivestreams.Publisher<T>>
A decorator that applies the fallback logic for reactive operator.
Users need to call
decorate(UnaryOperator) and provide the operator to decorate after instantiating
a ReactorOperatorFallbackDecorator with the desired fallback publisher.-
Method Summary
Modifier and TypeMethodDescriptionorg.reactivestreams.Publisher<T>decorate(UnaryOperator<org.reactivestreams.Publisher<T>> operator) Applies the fallback behavior to the provided operatorstatic <T> Function<org.reactivestreams.Publisher<T>,org.reactivestreams.Publisher<T>> decorateCircuitBreaker(CircuitBreakerOperator<T> circuitBreakerOperator, org.reactivestreams.Publisher<T> fallbackPublisher) a convenience method that initializes a default circuitbreaker fallback behavior (afterCallNotPermittedExceptionis thrownstatic <T> Function<org.reactivestreams.Publisher<T>,org.reactivestreams.Publisher<T>> decorateRetry(RetryOperator<T> retryOperator, org.reactivestreams.Publisher<T> fallbackPublisher) a convenience method that initializes a default retry fallback behavior (afterMaxRetriesExceededExceptionis thrownstatic <T> Function<org.reactivestreams.Publisher<T>,org.reactivestreams.Publisher<T>> decorateTimeLimiter(TimeLimiterOperator<T> timeLimiterOperator, org.reactivestreams.Publisher<T> fallbackPublisher) a convenience method that initializes a default timelimiter fallback behavior (afterTimeoutExceptionis thrownstatic <T> ReactorOperatorFallbackDecorator<T>Initializes aReactorOperatorFallbackDecoratorthat will fallback when the publisher finishes with an error of the provided class.withFallback(Class<? extends Throwable> throwableType, org.reactivestreams.Publisher<T> fallback) Adds a fallback publisher that will be used if the underline publisher completes with on error of this fallbackThrowable type
-
Method Details
-
withFallback
public ReactorOperatorFallbackDecorator<T> withFallback(Class<? extends Throwable> throwableType, org.reactivestreams.Publisher<T> fallback) Adds a fallback publisher that will be used if the underline publisher completes with on error of this fallbackThrowable type- Parameters:
throwableType- the type of throwable that triggers the fallbackfallback- the publisher to subscribe to when a Throwable of type throwableClass is thrown- Returns:
- the function to apply to the stream (typically by calling {
Mono.transformDeferred(Function)} orFlux.transformDeferred(Function)
-
of
public static <T> ReactorOperatorFallbackDecorator<T> of(Class<? extends Throwable> throwableType, org.reactivestreams.Publisher<T> fallback) Initializes aReactorOperatorFallbackDecoratorthat will fallback when the publisher finishes with an error of the provided class.- Type Parameters:
T- the value type of the upstream and downstream- Parameters:
throwableType- the type of throwable that triggers the fallbackfallback- the publisher to subscribe to when a Throwable of type throwableClass is thrown- Returns:
- ReactorOperatorFallbackDecorator that can be used to decorate an operator with fallback
- See Also:
-
apply
-
decorate
public Function<org.reactivestreams.Publisher<T>,org.reactivestreams.Publisher<T>> decorate(UnaryOperator<org.reactivestreams.Publisher<T>> operator) Applies the fallback behavior to the provided operator- Parameters:
operator- the operator to decorate with this fallback- Returns:
- the function to apply to the stream, typically by calling
Mono.transformDeferred(Function)orFlux.transformDeferred(Function)
-
decorateRetry
public static <T> Function<org.reactivestreams.Publisher<T>,org.reactivestreams.Publisher<T>> decorateRetry(RetryOperator<T> retryOperator, org.reactivestreams.Publisher<T> fallbackPublisher) a convenience method that initializes a default retry fallback behavior (afterMaxRetriesExceededExceptionis thrown- Type Parameters:
T- the value type of the upstream and downstream- Parameters:
retryOperator- the operator to decorate with fallbackPublisherfallbackPublisher- the publisher to use whenMaxRetriesExceededExceptionis thrown- Returns:
- the function to apply to the stream, typically by calling
Mono.transformDeferred(Function)orFlux.transformDeferred(Function)
-
decorateCircuitBreaker
public static <T> Function<org.reactivestreams.Publisher<T>,org.reactivestreams.Publisher<T>> decorateCircuitBreaker(CircuitBreakerOperator<T> circuitBreakerOperator, org.reactivestreams.Publisher<T> fallbackPublisher) a convenience method that initializes a default circuitbreaker fallback behavior (afterCallNotPermittedExceptionis thrown- Type Parameters:
T- the value type of the upstream and downstream- Parameters:
circuitBreakerOperator- the operator to decorate with fallbackPublisherfallbackPublisher- the publisher to use whenCallNotPermittedExceptionis thrown- Returns:
- the function to apply to the stream, typically by calling
Mono.transformDeferred(Function)orFlux.transformDeferred(Function)
-
decorateTimeLimiter
public static <T> Function<org.reactivestreams.Publisher<T>,org.reactivestreams.Publisher<T>> decorateTimeLimiter(TimeLimiterOperator<T> timeLimiterOperator, org.reactivestreams.Publisher<T> fallbackPublisher) a convenience method that initializes a default timelimiter fallback behavior (afterTimeoutExceptionis thrown- Type Parameters:
T- the value type of the upstream and downstream- Parameters:
timeLimiterOperator- the operator to decorate with fallbackPublisherfallbackPublisher- the publisher to use whenTimeoutExceptionis thrown- Returns:
- the function to apply to the stream, typically by calling
Mono.transformDeferred(Function)orFlux.transformDeferred(Function)
-