Class RateLimiterRequestHandlerAdvice
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
org.springframework.integration.handler.advice.RateLimiterRequestHandlerAdvice
- All Implemented Interfaces:
Advice
,Interceptor
,MethodInterceptor
,Aware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,ComponentSourceAware
,ExpressionCapable
,NamedComponent
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
AMessagingException
wrapper for theRequestNotPermitted
with therequestMessage
andtarget
context.Nested classes/interfaces inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
AbstractRequestHandlerAdvice.ExecutionCallback, AbstractRequestHandlerAdvice.ThrowableHolderException
-
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
ConstructorDescriptionConstruct an instance based on default rate limiter options and "RateLimiterRequestHandlerAdvice" as a rate limiter name.RateLimiterRequestHandlerAdvice
(io.github.resilience4j.ratelimiter.RateLimiter rateLimiter) Construct an instance based on the providedRateLimiter
.RateLimiterRequestHandlerAdvice
(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig) Construct an instance based on the providedRateLimiterConfig
and "RateLimiterRequestHandlerAdvice" as a rate limiter name.RateLimiterRequestHandlerAdvice
(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig, String name) Construct an instance based on the providedRateLimiterConfig
and name.Construct an instance based on default rate limiter options and provided name. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
doInvoke
(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Subclasses implement this method to apply behavior to theMessageHandler
.io.github.resilience4j.ratelimiter.RateLimiter.Metrics
Obtain the metrics from the rate limiter.io.github.resilience4j.ratelimiter.RateLimiter
Get theRateLimiter
which is configured for this advice.void
setLimitForPeriod
(int limitForPeriod) Change thelimitForPeriod
option of therateLimiter
.void
setTimeoutDuration
(Duration timeoutDuration) Change thetimeoutDuration
option of therateLimiter
.Methods inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
invoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessary
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getComponentType, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, onInit, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
-
Field Details
-
DEFAULT_NAME
- See Also:
-
-
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
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 providedRateLimiter
.- Parameters:
rateLimiter
- theRateLimiter
to use.
-
RateLimiterRequestHandlerAdvice
public RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig) Construct an instance based on the providedRateLimiterConfig
and "RateLimiterRequestHandlerAdvice" as a rate limiter name.- Parameters:
rateLimiterConfig
- theRateLimiterConfig
to use.
-
RateLimiterRequestHandlerAdvice
public RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig, String name) Construct an instance based on the providedRateLimiterConfig
and name.- Parameters:
rateLimiterConfig
- theRateLimiterConfig
to use.name
- the name for the rate limiter.
-
-
Method Details
-
setLimitForPeriod
public void setLimitForPeriod(int limitForPeriod) Change thelimitForPeriod
option of therateLimiter
.- Parameters:
limitForPeriod
- thelimitForPeriod
to use.- See Also:
-
RateLimiter.changeLimitForPeriod(int)
-
setTimeoutDuration
Change thetimeoutDuration
option of therateLimiter
.- Parameters:
timeoutDuration
- thetimeoutDuration
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 theRateLimiter
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 theMessageHandler
.callback.execute() invokes the handler method and returns its result, or null.
- Specified by:
doInvoke
in classAbstractRequestHandlerAdvice
- 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
.
-