sulu/messenger

这个库提供了邮票、中间件以及sulu消息总线。

维护者

详细信息

github.com/sulu/messenger

源代码

问题

安装次数: 19,035

依赖项: 0

建议者: 0

安全性: 0

星标: 6

关注者: 5

分支: 3

开放问题: 0

类型:sulu-bundle

0.2.4 2024-08-08 13:47 UTC

This package is auto-updated.

Last update: 2024-09-08 14:03:02 UTC


README

Official Sulu Bundle Badge

GitHub license GitHub tag (latest SemVer) Test workflow status Sulu compatibility


这个库提供了邮票和中间件,用于配置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消息总线中激活。