A Java library for rate limiting, offering both Token Bucket and Leaky Bucket algorithms. Designed for easy integration into your Java, Maven, or Spring Boot projects.
- Token Bucket Algorithm: Flexible rate limiting with burst capability.
- Leaky Bucket Algorithm: Smooth, steady rate limiting for consistent throughput.
- Modular and extensible: Easily extend and integrate with your own services.
- Suitable for API request limiting, resource usage throttling, and more.
Add the library to your Maven project:
<dependency>
<groupId>com.yourorg</groupId>
<artifactId>rateLimiter</artifactId>
<version>1.0.0</version>
</dependency>Replace com.yourorg and 1.0.0 with the actual group ID and version if different.
Extend the provided implementations or integrate the core classes directly into your application. Example (pseudo-code):
// Token Bucket Example
TokenBucketRateLimiter limiter = new TokenBucketRateLimiter(100, 10); // capacity, refill rate
if (limiter.allowRequest()) {
// process request
}
// Leaky Bucket Example
LeakyBucketRateLimiter limiter = new LeakyBucketRateLimiter(50, 5); // capacity, outflow rate
if (limiter.allowRequest()) {
// process request
}You can autowire or instantiate the rate limiter within your Spring services or controllers as needed. Customize or extend the base classes to fit your requirements.
- Implement custom logic by extending the provided classes.
- Override the
allowRequest()or relevant methods. - Integrate with your APIs, background jobs, or any rate-limited resource.
Contributions are welcome! Please fork the repo and submit pull requests. For major changes, open an issue first to discuss your ideas.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or support, please open an issue.