Download the PHP package agluh/outbox-bundle without Composer
On this page you can find all versions of the php package agluh/outbox-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download agluh/outbox-bundle
More information about agluh/outbox-bundle
Files in agluh/outbox-bundle
Package outbox-bundle
Short Description Implements Outbox pattern for DDD-based Symfony applications
License MIT
Informations about the package outbox-bundle
Outbox bundle
Implements Outbox pattern for DDD-based Symfony applications.
How it works:
- Bundle collects domain events from aggregate being persisted and save them in a separate table within a single database transaction.
- After a successful commit those domain events are enqueued for publication.
- If bundle configured with
auto_publish=true
option, then domain events from outbox table will be processed using a Symfony event listener in the kernel.TERMINATE or console.TERMINATE events. - If bundle configured with
auto_publish=false
option, then you should use CLI interface described below to periodically run worker for processing of stored events.
- If bundle configured with
Important note: events are enqueued for publishing on-by-one in ascending order sorted by expected publication date (witch by default is date of registration domain event in outbox). If for some reason on DomainEventEnqueuedForPublishingEvent you did not marked domain event as published (i.e. publication date not set) then next time outbox will try to enqueue for publishing the same domain event until it succeeded. This ensures time consistency of published domain events.
Note: you can combine auto publishing with CLI-based publication at the same time. Locking mechanism ensure all events will be published in the right order.
Acknowledgments
Inspired by Domain Event Bundle. Worker class mainly based on Worker from symfony/messenger component.
Installation
Requires Symfony 4.4, or Symfony 5.x and PHP 7.4 and above
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
Usage
Outbox bundle integrates into your Symfony application mostly by application events. You should implement listeners for them as shown below.
Console commands
Publish domain events
The php process is not designed to work for a long time. So it has to quit periodically. Or, the command may exit because of error or exception. Something has to bring it back and continue events publication (if not used auto publication). You can use Supervisord for that. It starts processes and keep an eye on them while they are working.
Here an example of supervisord configuration.
Note: Pay attention to --time-limit it tells the command to exit after 60 minutes.
Prune published domain events
Stop workers
Custom serializer
By default, outbox bundle uses serialize/unserialize functions from PHP to convert domain event to a string during persistence. You can use a custom serializer for that purpose. For example, how to use symfony/serializer is shown below.
Then register new serializer as a service.
Default configuration
Contributing
Contributions are welcome. Composer scripts are configured for your convenience:
All versions of outbox-bundle with dependencies
symfony/lock Version ^4.4 || ^5.0
symfony/framework-bundle Version ^4.4 || ^5.0
symfony/console Version ^4.4 || ^5.0
doctrine/doctrine-bundle Version ^1.0 || ^2.0
doctrine/orm Version ^2.6
ramsey/uuid-doctrine Version ^1.6
webmozart/assert Version ^1.9