rekalogika / domain-event-outbox
Implementation of the transactional outbox pattern on top of rekalogika/domain-event
Fund package maintenance!
priyadi
Installs: 608
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
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
Implementation of the transactional outbox pattern on top of the
rekalogika/domain-event
package.
Full documentation is available at rekalogika.dev/domain-event.
Synopsis
// // 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.
Documentation
License
MIT
Contributing
The rekalogika/domain-event-outbox
repository is a read-only repo split from
the main repo. Issues and pull requests should be submitted to the
rekalogika/domain-event-src
monorepo.