The RateLimitJ Inmemory module provides an implementation of a configurable sliding window rate limiting algorithm.
The Inmemory Module supports (RequestRateLimiter)[], (ConcurrentRequestLimiter)[] interfaces.
<dependency>
<groupId>es.moki.ratelimitj</groupId>
<artifactId>ratelimitj-inmemory</artifactId>
<version>${ratelimitj-inmemory.version}</version>
</dependency>
import es.moki.ratelimitj.inmemory.request.InMemorySlidingWindowRequestRateLimiter;
Set<RequestLimitRule> rules = Collections.singleton(RequestLimitRule.of(Duration.ofMinutes(1), 50)); // 50 request per minute, per key
RequestRateLimiter requestRateLimiter = new InMemorySlidingWindowRequestRateLimiter(rules);
boolean overLimit = requestRateLimiter.overLimitWhenIncremented("ip:127.0.0.2");
- Java 8