rekalogika / domain-event-outbox
基于 rekalogika/domain-event 实现的事务型出盒模式
2.5.0
2024-09-16 15:46 UTC
Requires
- doctrine/doctrine-bundle: ^2.11.3 || ^2.12
- doctrine/orm: ^2.16 || ^3.0
- doctrine/persistence: ^3.2
- rekalogika/domain-event: ^2.5
- rekalogika/domain-event-contracts: ^2.5
- symfony/config: ^6.4 || ^7.0
- symfony/dependency-injection: ^6.4 || ^7.0
- symfony/http-kernel: ^6.4 || ^7.0
- symfony/lock: ^6.4 || ^7.0
- symfony/messenger: ^6.4 || ^7.0
README
在 rekalogika/domain-event
包的基础上实现了事务型出盒模式。
完整文档可在 rekalogika.dev/domain-event 查找。
概要
// // The event // final readonly class PostChanged { public function __construct(public string $postId) {} } // // The entity // use Rekalogika\Contracts\DomainEvent\DomainEventEmitterInterface; use Rekalogika\Contracts\DomainEvent\DomainEventEmitterTrait; class Post implements DomainEventEmitterInterface { use DomainEventEmitterTrait; // ... public function setTitle(string $title): void { $this->title = $title; // highlight-next-line $this->recordEvent(new PostChanged($this->id)); } // ... } // // The listener // use Psr\Log\LoggerInterface; use Rekalogika\Contracts\DomainEvent\Attribute\AsPublishedDomainEventListener; class PostEventListener { public function __construct(private LoggerInterface $logger) {} // highlight-next-line #[AsPublishedDomainEventListener] public function onPostChanged(PostChanged $event) { $postId = $event->postId; $this->logger->info("Post $postId has been changed."); } } // // The caller // use Doctrine\ORM\EntityManagerInterface; /** @var Post $post */ /** @var EntityManagerInterface $entityManager */ $post->setTitle('New title'); $entityManager->flush(); // During the flush above, the event will be recorded in the outbox table in the // database. Then the message relay service is executed, and will publish the // events on the event bus. When the event bus announces the event, the listener // will be executed.
文档
许可证
MIT
贡献
rekalogika/domain-event-outbox
仓库是从主仓库拆分出的只读仓库。问题和拉取请求应提交到 rekalogika/domain-event-src monorepo。