Class FeignDecorators

  • All Implemented Interfaces:
    FeignDecorator

    public class FeignDecorators
    extends java.lang.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 Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static FeignDecorators.Builder builder()  
      io.vavr.CheckedFunction1<java.lang.Object[],​java.lang.Object> decorate​(io.vavr.CheckedFunction1<java.lang.Object[],​java.lang.Object> fn, java.lang.reflect.Method method, feign.InvocationHandlerFactory.MethodHandler methodHandler, feign.Target<?> target)
      Decorates the invocation of a method defined by a feign interface.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • decorate

        public io.vavr.CheckedFunction1<java.lang.Object[],​java.lang.Object> decorate​(io.vavr.CheckedFunction1<java.lang.Object[],​java.lang.Object> fn,
                                                                                            java.lang.reflect.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