The Rate Limiter middleware is designed to control traffic by limiting the number of requests and managing queues for each endpoint and user. This middleware is implemented in Go and provides flexible configurations to handle various traffic scenarios.
This middleware is based on another throttle middleware: joegarb/traefik-throttle
The Rate Limiter middleware requires a configuration file specifying global and endpoint-specific rate limiting rules.
maxRequests: 10maxQueue: 5retryCount: 3retryDelay: "500ms"userMaxRequests: 2userRetryDelay: "1s"endpoints:"/api/v1/resource":GET:maxRequests: 20maxQueue: 10retryCount: 5retryDelay: "200ms"userMaxRequests: 5userRetryDelay: "500ms"POST:maxRequests: 10maxQueue: 5retryCount: 3retryDelay: "300ms"userMaxRequests: 3userRetryDelay: "1s"
To use the Rate Limiter middleware as a Traefik plugin, follow these steps:
Enable the plugin in your Traefik configuration:
experimental:plugins:rateLimiter:moduleName: "github.com/iolabs-ag/ratelimiter"version: "v1.0.0"
Configure the middleware in the Traefik dynamic configuration file:
http:middlewares:rate-limiter:plugin:rateLimiter:maxRequests: 10maxQueue: 5retryCount: 3retryDelay: "500ms"userMaxRequests: 2userRetryDelay: "1s"endpoints:"/api/v1/resource":GET:maxRequests: 20maxQueue: 10retryCount: 5retryDelay: "200ms"userMaxRequests: 5userRetryDelay: "500ms"
Attach the middleware to a Traefik router:
http:routers:my-router:rule: "PathPrefix(`/api`)"service: my-servicemiddlewares:- rate-limiter
The middleware uses centralized logging with levels:
Contributions are welcome! Please submit a pull request or open an issue for any improvements or bug reports.
This middleware is licensed under the MIT License. See the LICENSE file for details.