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
Nested ClassesModifier and TypeClassDescriptionstatic classAMessagingExceptionwrapper for theRequestNotPermittedwith therequestMessageandtargetcontext.Nested classes/interfaces inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
AbstractRequestHandlerAdvice.ExecutionCallback, AbstractRequestHandlerAdvice.ThrowableHolderException -
Field Summary
FieldsFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger -
Constructor Summary
ConstructorsConstructorDescriptionConstruct 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 providedRateLimiterConfigand "RateLimiterRequestHandlerAdvice" as a rate limiter name.RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig, String name) Construct an instance based on the providedRateLimiterConfigand name.Construct an instance based on default rate limiter options and provided name. -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectdoInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Subclasses implement this method to apply behavior to theMessageHandler.io.github.resilience4j.ratelimiter.RateLimiter.MetricsObtain the metrics from the rate limiter.io.github.resilience4j.ratelimiter.RateLimiterGet theRateLimiterwhich is configured for this advice.voidsetLimitForPeriod(int limitForPeriod) Change thelimitForPeriodoption of therateLimiter.voidsetTimeoutDuration(Duration timeoutDuration) Change thetimeoutDurationoption of therateLimiter.Methods inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
invoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessaryMethods 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:
-
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- theRateLimiterto use.
-
RateLimiterRequestHandlerAdvice
public RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig) Construct an instance based on the providedRateLimiterConfigand "RateLimiterRequestHandlerAdvice" as a rate limiter name.- Parameters:
rateLimiterConfig- theRateLimiterConfigto use.
-
RateLimiterRequestHandlerAdvice
public RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig, String name) Construct an instance based on the providedRateLimiterConfigand name.- Parameters:
rateLimiterConfig- theRateLimiterConfigto use.name- the name for the rate limiter.
-
-
Method Details
-
setLimitForPeriod
public void setLimitForPeriod(int limitForPeriod) Change thelimitForPeriodoption of therateLimiter.- Parameters:
limitForPeriod- thelimitForPeriodto use.- See Also:
-
setTimeoutDuration
Change thetimeoutDurationoption of therateLimiter.- Parameters:
timeoutDuration- thetimeoutDurationto use.- See Also:
-
getMetrics
public io.github.resilience4j.ratelimiter.RateLimiter.Metrics getMetrics()Obtain the metrics from the rate limiter.- Returns:
- the
RateLimiter.Metricsfrom rate limiter. - See Also:
-
getRateLimiter
public io.github.resilience4j.ratelimiter.RateLimiter getRateLimiter()Get theRateLimiterwhich is configured for this advice.- Returns:
- the
RateLimiterfor this advice.
-
doInvoke
protected Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Description copied from class:AbstractRequestHandlerAdviceSubclasses implement this method to apply behavior to theMessageHandler.callback.execute() invokes the handler method and returns its result, or null.
- Specified by:
doInvokein 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.
-