Class RateLimiterRequestHandlerAdvice

java.lang.Object
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.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
  • 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​(java.lang.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, java.lang.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​(java.time.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 java.lang.Object doInvoke​(AbstractRequestHandlerAdvice.ExecutionCallback callback, java.lang.Object target, org.springframework.messaging.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.