Usage is as simple as
composer require lamoda/tactician-rate-limit
After that you need to choose library that is providing rate limiting capabilities. For now there out of the box support for the following libraries:
To use this library do the following:
- Require
stiphle
via composer:composer require davedevelopment/stiphle
- Configure middleware:
$rateLimitProvider = new MatchingCommandClassRateLimitProvider( RateLimitedCommand::class, 3, // max commands to execute per interval 1000 // interval in milliseconds ); $rateLimiter = new StiphleRateLimiterAdapter(new LeakyBucket()); $rateLimitMiddleware = new RateLimitMiddleware( $rateLimitProvider, $rateLimiter ); // Create command bus with this middleware: $commandBus = new CommandBus([ $rateLimitMiddleware, // other middlewares ]);
If you are using Symfony: use lamoda/tactician-rate-limit-bundle