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 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 fallback
      fallback - 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)} or Flux.transformDeferred(Function)
    • of

      public static <T> ReactorOperatorFallbackDecorator<T> of(Class<? extends Throwable> throwableType, org.reactivestreams.Publisher<T> fallback)
      Initializes a ReactorOperatorFallbackDecorator that 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 fallback
      fallback - 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

      public org.reactivestreams.Publisher<T> apply(org.reactivestreams.Publisher<T> publisher)
      Specified by:
      apply in interface Function<org.reactivestreams.Publisher<T>,org.reactivestreams.Publisher<T>>
    • 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) or Flux.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 (after MaxRetriesExceededException is thrown
      Type Parameters:
      T - the value type of the upstream and downstream
      Parameters:
      retryOperator - the operator to decorate with fallbackPublisher
      fallbackPublisher - the publisher to use when MaxRetriesExceededException is thrown
      Returns:
      the function to apply to the stream, typically by calling Mono.transformDeferred(Function) or Flux.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 (after CallNotPermittedException is thrown
      Type Parameters:
      T - the value type of the upstream and downstream
      Parameters:
      circuitBreakerOperator - the operator to decorate with fallbackPublisher
      fallbackPublisher - the publisher to use when CallNotPermittedException is thrown
      Returns:
      the function to apply to the stream, typically by calling Mono.transformDeferred(Function) or Flux.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 (after TimeoutException is thrown
      Type Parameters:
      T - the value type of the upstream and downstream
      Parameters:
      timeLimiterOperator - the operator to decorate with fallbackPublisher
      fallbackPublisher - the publisher to use when TimeoutException is thrown
      Returns:
      the function to apply to the stream, typically by calling Mono.transformDeferred(Function) or Flux.transformDeferred(Function)