Class FeignDecorators

java.lang.Object
io.github.resilience4j.feign.FeignDecorators
All Implemented Interfaces:
FeignDecorator

public class FeignDecorators extends Object implements FeignDecorator
Builder to help build stacked decorators.
 {
     @code
     CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("backendName");
     RateLimiter rateLimiter = RateLimiter.ofDefaults("backendName");
     FeignDecorators decorators = FeignDecorators.builder()
             .withCircuitBreaker(circuitBreaker)
             .withRateLimiter(rateLimiter)
             .build();
     MyService myService = Resilience4jFeign.builder(decorators).target(MyService.class, "http://localhost:8080/");
 }
 

The order in which decorators are applied correspond to the order in which they are declared. For example, calling FeignDecorators.Builder.withFallback(Object) before FeignDecorators.Builder.withCircuitBreaker(CircuitBreaker) would mean that the fallback is called when the HTTP request fails, but would no longer be reachable if the CircuitBreaker were open. However, reversing the order would mean that the fallback is called both when the HTTP request fails and when the CircuitBreaker is open.
So be wary of this when designing your "resilience" strategy.

  • Method Details

    • builder

      public static FeignDecorators.Builder builder()
    • decorate

      public io.github.resilience4j.core.functions.CheckedFunction<Object[],Object> decorate(io.github.resilience4j.core.functions.CheckedFunction<Object[],Object> fn, Method method, feign.InvocationHandlerFactory.MethodHandler methodHandler, feign.Target<?> target)
      Description copied from interface: FeignDecorator
      Decorates the invocation of a method defined by a feign interface.
      Specified by:
      decorate in interface FeignDecorator
      Parameters:
      fn - represents the call to the method. This should be decorated by the implementing class.
      method - the method of the feign interface that is invoked.
      methodHandler - the feign methodHandler that executes the http request.
      Returns:
      the decorated invocationCall