Class RateLimiterRequestHandlerAdvice

All Implemented Interfaces:
Advice, Interceptor, MethodInterceptor, Aware, BeanFactoryAware, BeanNameAware, InitializingBean, ApplicationContextAware, ExpressionCapable, NamedComponent

public class RateLimiterRequestHandlerAdvice extends AbstractRequestHandlerAdvice
An AbstractRequestHandlerAdvice extension for a rate limiting to service method calls. The implementation is based on the Resilience4j.
Since:
5.2
Author:
Artem Bilan, Gary Russell
  • Field Details

  • Constructor Details

    • RateLimiterRequestHandlerAdvice

      public RateLimiterRequestHandlerAdvice()
      Construct an instance based on default rate limiter options and "RateLimiterRequestHandlerAdvice" as a rate limiter name.
      See Also:
      • RateLimiter.ofDefaults(java.lang.String)
    • RateLimiterRequestHandlerAdvice

      public RateLimiterRequestHandlerAdvice(String name)
      Construct an instance based on default rate limiter options and provided name.
      Parameters:
      name - the name for the rate limiter.
    • RateLimiterRequestHandlerAdvice

      public RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiter rateLimiter)
      Construct an instance based on the provided RateLimiter.
      Parameters:
      rateLimiter - the RateLimiter to use.
    • RateLimiterRequestHandlerAdvice

      public RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig)
      Construct an instance based on the provided RateLimiterConfig and "RateLimiterRequestHandlerAdvice" as a rate limiter name.
      Parameters:
      rateLimiterConfig - the RateLimiterConfig to use.
    • RateLimiterRequestHandlerAdvice

      public RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig, String name)
      Construct an instance based on the provided RateLimiterConfig and name.
      Parameters:
      rateLimiterConfig - the RateLimiterConfig to use.
      name - the name for the rate limiter.
  • Method Details

    • setLimitForPeriod

      public void setLimitForPeriod(int limitForPeriod)
      Change the limitForPeriod option of the rateLimiter.
      Parameters:
      limitForPeriod - the limitForPeriod to use.
      See Also:
      • RateLimiter.changeLimitForPeriod(int)
    • setTimeoutDuration

      public void setTimeoutDuration(Duration timeoutDuration)
      Change the timeoutDuration option of the rateLimiter.
      Parameters:
      timeoutDuration - the timeoutDuration to use.
      See Also:
      • RateLimiter.changeTimeoutDuration(Duration)
    • getMetrics

      public io.github.resilience4j.ratelimiter.RateLimiter.Metrics getMetrics()
      Obtain the metrics from the rate limiter.
      Returns:
      the RateLimiter.Metrics from rate limiter.
      See Also:
      • RateLimiter.getMetrics()
    • getRateLimiter

      public io.github.resilience4j.ratelimiter.RateLimiter getRateLimiter()
      Get the RateLimiter which is configured for this advice.
      Returns:
      the RateLimiter for this advice.
    • doInvoke

      protected Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message)
      Description copied from class: AbstractRequestHandlerAdvice
      Subclasses implement this method to apply behavior to the MessageHandler.

      callback.execute() invokes the handler method and returns its result, or null.

      Specified by:
      doInvoke in class AbstractRequestHandlerAdvice
      Parameters:
      callback - Subclasses invoke the execute() method on this interface to invoke the handler method.
      target - The target handler.
      message - The message that will be sent to the handler.
      Returns:
      the result after invoking the MessageHandler.