creatortsv/symfony-messenger-outbox-pattern
最新稳定版本:v1.1.0
Composer 安装命令:
composer require creatortsv/symfony-messenger-outbox-pattern
包简介
Outbox pattern for the symfony-messenger component
README 文档
README
This package is an extension for the symfony/messenger component that implements the Transactional outbox pattern. It provides the special middleware that navigates your original message to the message broker through the outbox transport
Requirements
| PHP | >=8.2 |
|---|---|
| symfony/contracts | >=2.5 |
| symfony/messenger | >=6.4 |
Installation
Install with composer
composer require creatortsv/symfony-messenger-outbox-pattern
Configuration
This guide shows how the symfony messenger component should be configured
Configure transports
# config/packages/messenger.yaml framework: messenger: transports: ### Your default async message transport for any purpose async: '%env(resolve:MESSENGER_TRANSPORT_DNS)%' ### Outbox transport, for example: ### outbox: '%env(resolve:MESSENGER_TRANSPORT_DNS)%' ### outbox: 'doctrine://%env(resolve:DATABASE_URL)%' ### outbox: 'doctrine://default?table_name=outbox&queue_name=custom' outbox: 'doctrine://default' ### Advance stored outbox transport stored: ### routing: ...
Configure message bus
# config/packages/messenger.yaml framework: messenger: buses: ### Configure message bus that will be used with middleware from this package event.bus: ### Default middlewares must be enabled default_middleware: enabled: true allow_no_handlers: true middleware: ### Add the middleware with configured outbox transport name or/and advanced names ### - Creatortsv\Messenger\Outbox\Middleware\SwitchToOutboxMiddleware: [ outbox, store, logs ] - Creatortsv\Messenger\Outbox\Middleware\SwitchToOutboxMiddleware: [ outbox ] ### transports: ... Outbox transport configuration ### routing: ...
Usage
readonly class UserService { public function __construct( private EntityManagerInterface $entityManager, private MessageBusInterface $eventBus, ) { // ... } public function register(User $user): void { $this->entityManager->wrapInTransaction( function () use ($user): void { /** Persist user in DB ... */ $this->entityManager->flush(); $this->eventBus->dispatch(new UserRegistered($user->id)); }, ); } }
Run outbox consumer
Run consumer with outbox transport name
php bin/console messenger:consume [name]
Each message which is consumed by the worker will be automatically sent to the original transport, thanks to the SwitchToOutboxMiddleware class
统计信息
- 总下载量: 4.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-12