public class RateLimiterRequestHandlerAdvice extends AbstractRequestHandlerAdvice
AbstractRequestHandlerAdvice
extension for a rate limiting to service method calls.
The implementation is based on the
Resilience4j.Modifier and Type | Class and Description |
---|---|
static class |
RateLimiterRequestHandlerAdvice.RateLimitExceededException
A
MessagingException wrapper for the RequestNotPermitted
with the requestMessage and target context. |
AbstractRequestHandlerAdvice.ExecutionCallback, AbstractRequestHandlerAdvice.ThrowableHolderException
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_NAME |
EXPRESSION_PARSER, logger
Constructor and Description |
---|
RateLimiterRequestHandlerAdvice()
Construct 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 provided
RateLimiter . |
RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig)
Construct an instance based on the provided
RateLimiterConfig
and "RateLimiterRequestHandlerAdvice" as a rate limiter name. |
RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig,
String name)
Construct an instance based on the provided
RateLimiterConfig and name. |
RateLimiterRequestHandlerAdvice(String name)
Construct an instance based on default rate limiter options and provided name.
|
Modifier and Type | Method and Description |
---|---|
protected Object |
doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback,
Object target,
Message<?> message)
Subclasses implement this method to apply behavior to the
MessageHandler . |
io.github.resilience4j.ratelimiter.RateLimiter.Metrics |
getMetrics()
Obtain the metrics from the rate limiter.
|
io.github.resilience4j.ratelimiter.RateLimiter |
getRateLimiter()
Get the
RateLimiter which is configured for this advice. |
void |
setLimitForPeriod(int limitForPeriod)
Change the
limitForPeriod option of the rateLimiter . |
void |
setTimeoutDuration(java.time.Duration timeoutDuration)
Change the
timeoutDuration option of the rateLimiter . |
invoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessary
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getComponentType, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, onInit, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
public static final String DEFAULT_NAME
public RateLimiterRequestHandlerAdvice()
RateLimiter.ofDefaults(java.lang.String)
public RateLimiterRequestHandlerAdvice(String name)
name
- the name for the rate limiter.public RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiter rateLimiter)
RateLimiter
.rateLimiter
- the RateLimiter
to use.public RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig)
RateLimiterConfig
and "RateLimiterRequestHandlerAdvice" as a rate limiter name.rateLimiterConfig
- the RateLimiterConfig
to use.public RateLimiterRequestHandlerAdvice(io.github.resilience4j.ratelimiter.RateLimiterConfig rateLimiterConfig, String name)
RateLimiterConfig
and name.rateLimiterConfig
- the RateLimiterConfig
to use.name
- the name for the rate limiter.public void setLimitForPeriod(int limitForPeriod)
limitForPeriod
option of the rateLimiter
.limitForPeriod
- the limitForPeriod
to use.RateLimiter.changeLimitForPeriod(int)
public void setTimeoutDuration(java.time.Duration timeoutDuration)
timeoutDuration
option of the rateLimiter
.timeoutDuration
- the timeoutDuration
to use.RateLimiter.changeTimeoutDuration(Duration)
public io.github.resilience4j.ratelimiter.RateLimiter.Metrics getMetrics()
RateLimiter.Metrics
from rate limiter.RateLimiter.getMetrics()
public io.github.resilience4j.ratelimiter.RateLimiter getRateLimiter()
RateLimiter
which is configured for this advice.RateLimiter
for this advice.protected Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message)
AbstractRequestHandlerAdvice
MessageHandler
.
callback.execute() invokes the handler method and returns its result, or null.
doInvoke
in class AbstractRequestHandlerAdvice
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.MessageHandler
.