Add rate-limit module: Bucket4j 8.21 token buckets on Redis in a Spring Boot 4.1 filter, per-user/per-key/global limits, 429 with Retry-After, two instances sharing one bucket

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7rnC7jppGGdHGESvy
This commit is contained in:
Claude
2026-10-28 18:27:06 +00:00
parent 99a8a0df42
commit fd0cf9b527
37 changed files with 1705 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
== two JVMs (A on 8081, B on 8082), one redis-server on 6411; free-key-123 allows 5 per minute
request 1 to :8081 -> 200
request 2 to :8082 -> 200
request 3 to :8081 -> 200
request 4 to :8082 -> 200
request 5 to :8081 -> 200
request 6 to :8082 -> 429
$ curl -si -H 'X-API-Key: free-key-123' http://localhost:8081/api/hello
HTTP/1.1 429
X-RateLimit-Limit: 5
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 60
X-RateLimit-Scope: api-key
Retry-After: 12
Content-Type: application/problem+json
{"type":"about:blank","title":"Too Many Requests","status":429,"detail":"Rate limit exceeded for scope 'api-key'. Retry in 12 second(s).","retryAfterSeconds":12}
$ redis-cli -p 6411 --scan
rl:global
rl:key:ea39d5800282edc4