A multi-module Kotlin/Spring Boot sample that applies Bucket4j rate limiting in both Spring WebFlux and Spring MVC.
The shared core module provides JWT utilities, pricing plan rules, and common constants.
core: Shared bucket/plan logic, JWT provider, and constants.webflux: Reactive WebFlux application with aWebFilterrate limiter.webmvc: Servlet-based Web MVC application with aHandlerInterceptorrate limiter.
core/
src/main/kotlin/.../application/PricingPlanService.kt
src/main/kotlin/.../enumerated/PricingPlan.kt
src/main/kotlin/.../security/JWTProvider.kt
webflux/
src/main/kotlin/.../configuration/RateLimitInterceptor.kt
src/main/kotlin/.../presentation/DummyController.kt
src/main/resources/application.yaml
webmvc/
src/main/kotlin/.../configuration/RateLimitInterceptor.kt
src/main/kotlin/.../presentation/DummyController.kt
src/main/resources/application.yaml
http/request.http
- Buckets are created per token and cached.
- If the token is missing or invalid, the role is treated as
ANONYMOUS. - Pricing plan mapping:
ANONYMOUS-> FREE (20 requests/hour)USER-> BASIC (40 requests/hour)PREMIUM/ADMIN-> PROFESSIONAL (100 requests/hour)
- Response headers:
X-Rate-Limit-RemainingX-Rate-Limit-Retry-After-Seconds
./gradlew :webflux:bootRun./gradlew :webmvc:bootRun- WebFlux:
GET http://localhost:1009/webflux - Web MVC:
GET http://localhost:1013/webmvc
Sample HTTP requests are in http/request.http.