Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Latest commit

 

History

History
49 lines (38 loc) · 1.78 KB

README.md

File metadata and controls

49 lines (38 loc) · 1.78 KB

Lamoda Tactician Rate Limit Middleware

Build Status Scrutinizer Code Quality Code Coverage Build Status

Installation

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:

  1. Require stiphle via composer:
    composer require davedevelopment/stiphle
  2. 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