lamoda/tactician-rate-limit

此包已被弃用,不再维护。未建议替代包。

Tactician 命令总线中间件,用于限制命令执行速率

0.1.1 2019-03-01 17:19 UTC

This package is auto-updated.

Last update: 2023-05-29 01:14:59 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Build Status

安装

用法非常简单

composer require lamoda/tactician-rate-limit

之后,您需要选择提供速率限制功能的库。目前有以下库提供内置支持:

要使用此库,请执行以下操作

  1. 通过 composer 需求 stiphle
    composer require davedevelopment/stiphle
  2. 配置中间件
    $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
    ]);

如果您正在使用 Symfony:使用 lamoda/tactician-rate-limit-bundle