|
1 |
| -# 🫚 Gember MessageBus: Symfony Messenger |
| 1 | +# 🫚 Gember Message Bus: Symfony Messenger |
2 | 2 | [](LICENSE)
|
3 | 3 | [](http://www.php.net)
|
4 | 4 |
|
5 |
| -Gember MessageBus ([gember/event-sourcing](https://github.com/GemberPHP/event-sourcing)) implementation based on [symfony/messenger](https://github.com/symfony/messenger). |
| 5 | +[Gember Event Sourcing](https://github.com/GemberPHP/event-sourcing) Message Bus adapter based on [symfony/messenger](https://github.com/symfony/messenger). |
| 6 | + |
| 7 | +> All external dependencies in Gember Event Sourcing are organized into separate packages, |
| 8 | +> making it easy to swap out a vendor adapter for another. |
| 9 | +
|
| 10 | +## Installation |
| 11 | +Install with Composer: |
| 12 | +```bash |
| 13 | +composer gember/message-bus-symfony |
| 14 | +``` |
| 15 | + |
| 16 | +## Configuration |
| 17 | +Bind this adapter to the `EventBus` interface in your service definitions. |
| 18 | + |
| 19 | +### Examples |
| 20 | + |
| 21 | +#### Vanilla PHP |
| 22 | +```php |
| 23 | +use Gember\MessageBusSymfony\SymfonyEventBus; |
| 24 | +use Symfony\Component\Messenger\Handler\HandlersLocator; |
| 25 | +use Symfony\Component\Messenger\MessageBus; |
| 26 | +use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware; |
| 27 | + |
| 28 | +$finder = new SymfonyEventBus( |
| 29 | + new MessageBus([ // An EventBus configuration of your choice |
| 30 | + new HandleMessageMiddleware(new HandlersLocator([ |
| 31 | + SomeEvent::class => [SomeEventSubscriber::class], |
| 32 | + // ... |
| 33 | + ])), |
| 34 | + ]), |
| 35 | +); |
| 36 | +``` |
| 37 | + |
| 38 | +#### Symfony |
| 39 | +It is recommended to use the [Symfony bundle](https://github.com/GemberPHP/event-sourcing-symfony-bundle) to configure Gember Event Sourcing. |
| 40 | +With this bundle, the adapter is automatically set as the default for Event Bus. |
| 41 | + |
| 42 | +If you're not using the bundle, you can bind it directly to the `EventBus` interface. |
| 43 | + |
| 44 | +```yaml |
| 45 | +Gember\EventSourcing\Util\Messaging\MessageBus\EventBus: |
| 46 | + class: Gember\MessageBusSymfony\SymfonyEventBus |
| 47 | + arguments: |
| 48 | + - '@event.bus' # or any other defined Symfony event bus |
| 49 | +``` |
0 commit comments