Class RateLimitAutoConfiguration
java.lang.Object
tech.riemann.nif.starter.security.ratelimit.RateLimitAutoConfiguration
- All Implemented Interfaces:
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
@AutoConfiguration
@EnableConfigurationProperties(RateLimitConfigurationProperties.class)
public class RateLimitAutoConfiguration
extends Object
implements org.springframework.web.servlet.config.annotation.WebMvcConfigurer
限流自动配置类
负责自动配置限流组件,支持三种限流算法: 1. 令牌桶算法(Token Bucket) 2. 滑动窗口算法(Sliding Window) 3. 固定窗口算法(Fixed Window)
配置优先级: 1. @RateLimit注解配置(最高优先级) 2. 配置文件中的rules规则(按接口路径匹配) 3. 配置文件中的defaultConfig默认配置(最低优先级)
配置示例:
nif:
web:
rate-limit:
enabled: true
default:
permits-per-second: 10
algorithm: TOKEN_BUCKET
rules:
/api/login:
permits-per-minute: 5
/api/sms/send:
permits-per-hour: 10
- Author:
- Kerbores(kerbores@riemann.tech)
-
Constructor Summary
ConstructorsConstructorDescriptionRateLimitAutoConfiguration(org.springframework.beans.factory.ObjectProvider<tech.riemann.nif.web.ratelimit.RateLimitInterceptor> rateLimitInterceptorProvider) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer
addArgumentResolvers, addCorsMappings, addErrorResponseInterceptors, addFormatters, addResourceHandlers, addReturnValueHandlers, addViewControllers, configureApiVersioning, configureAsyncSupport, configureContentNegotiation, configureDefaultServletHandling, configureHandlerExceptionResolvers, configureMessageConverters, configureMessageConverters, configurePathMatch, configureViewResolvers, extendHandlerExceptionResolvers, extendMessageConverters, getMessageCodesResolver, getValidator
-
Constructor Details
-
RateLimitAutoConfiguration
public RateLimitAutoConfiguration(org.springframework.beans.factory.ObjectProvider<tech.riemann.nif.web.ratelimit.RateLimitInterceptor> rateLimitInterceptorProvider)
-
-
Method Details
-
addInterceptors
public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) - Specified by:
addInterceptorsin interfaceorg.springframework.web.servlet.config.annotation.WebMvcConfigurer
-