sulu / messenger
这个库提供了邮票、中间件以及sulu消息总线。
0.2.4
2024-08-08 13:47 UTC
Requires
- php: 8.0.* || 8.1.* || 8.2.* || 8.3.*
- doctrine/dbal: ^2.13 || ^3.0
- doctrine/doctrine-bundle: ^2.5
- doctrine/orm: ^2.11
- psr/container: ^1.0 || ^2.0
- symfony/config: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/doctrine-bridge: ^5.4 || ^6.0 || ^7.0
- symfony/framework-bundle: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
- symfony/lock: ^5.4 || ^6.0 || ^7.0
- symfony/messenger: ^5.4 || ^6.0 || ^7.0
- symfony/service-contracts: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- coduo/php-matcher: ^6.0
- friendsofphp/php-cs-fixer: ^3.6
- handcraftedinthealps/code-coverage-checker: ^0.2.5
- jangregor/phpstan-prophecy: ^1.0
- phpspec/prophecy-phpunit: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.4
- phpstan/phpstan-doctrine: ^1.2
- phpstan/phpstan-phpunit: ^1.0
- phpstan/phpstan-symfony: ^1.1
- phpstan/phpstan-webmozart-assert: ^1.0
- phpunit/phpunit: ^9.5
- qossmic/deptrac-shim: ^0.24.0 || ^1.0
- rector/rector: ^1.0
- schranz/test-generator: ^0.4
- symfony/browser-kit: ^5.4 || ^6.0 || ^7.0
- symfony/css-selector: ^5.4 || ^6.0 || ^7.0
- symfony/debug-bundle: ^5.4 || ^6.0 || ^7.0
- symfony/dotenv: ^5.4 || ^6.0 || ^7.0
- symfony/error-handler: ^5.4 || ^6.0 || ^7.0
- symfony/phpunit-bridge: ^5.4 || ^6.0 || ^7.0
- symfony/yaml: ^5.4 || ^6.0 || ^7.0
- thecodingmachine/phpstan-strict-rules: ^1.0
README
这个库提供了邮票和中间件,用于配置sulu消息总线。它可以在任何symfony安装中独立使用。
安装
请确保已经全局安装了Composer,具体请参考Composer文档中的安装章节。
打开命令行,进入项目目录并执行
composer require sulu/messenger
然后,通过将此捆绑包添加到项目config/bundles.php
文件中注册的捆绑包列表中,来启用此捆绑包
// config/bundles.php return [ // ... Sulu\Messenger\Infrastructure\Symfony\HttpKernel\SuluMessengerBundle::class => ['all' => true], ];
中间件
UnpackExceptionMiddleware
UnpackExceptionMiddleware
将解包由Symfony的HandleMessageMiddleware
创建的HandlerFailedException
。这样我们确保真正的异常由这个消息总线抛出,控制器可以捕获或将其转换为特定的http状态码。这个中间件始终在sulu消息总线中激活。
LockMiddleware
LockMiddleware
将允许通过给定的键锁定特定的资源。这通常用于防止对同一资源的并发访问和避免竞争条件。锁定可以通过支持与Symfony LockFactory
相同参数的LockStamp
激活和控制。
use Sulu\Messenger\Infrastructure\Symfony\Messenger\LockMiddleware\LockStamp; $this->handle(new Envelope(new YourMessage(), [new LockStamp('lock-key')])); # set ttl and autorelease $this->handle(new Envelope(new YourMessage(), [new LockStamp('lock-key', 300.0, true)])); # multiple locks possible all locks need to be acquired before processing the message $this->handle(new Envelope(new YourMessage(), [new LockStamp('lock-key-1'), new LockStamp('lock-key-2')]));
DoctrineFlushMiddleware
DoctrineFlushMiddleware
是一个中间件,它允许通过EnableFlushStamp
的opt-in标志刷新Doctrine EntityManager。它可以这样使用
use Sulu\Messenger\Infrastructure\Symfony\Messenger\FlushMiddleware\EnableFlushStamp; $this->handle(new Envelope(new YourMessage(), [new EnableFlushStamp()]));
这个中间件始终在sulu消息总线中激活。