Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 1.33 KB

event_bus.md

File metadata and controls

48 lines (37 loc) · 1.33 KB

Event Bus

This library uses the core principle called event bus.

For all events that are persisted (when the save method has been executed on the repository), the event will be dispatched to the event bus. All listeners are then called for each event.

Symfony Event Bus

To use the Symfony Messager, you have to define it in messenger.yaml. It's best to call the bus "event.bus". An event bus can have 0 or n listener for an event. So "allow_no_handlers" has to be configured.

framework:
    messenger:
        buses:
            event.bus:
                default_middleware: allow_no_handlers

We can then use this message or event bus in event sourcing:

patchlevel_event_sourcing:
    event_bus:
        service: event.bus

Command Bus

If you use a command bus or cqrs as a pattern, then you should define a new message bus. The whole thing can look like this:

framework:
    messenger:
        default_bus: command.bus
        buses:
            command.bus: ~
            event.bus:
                default_middleware: allow_no_handlers

⚠️ You should deactivate the autoconfigure feature for the handlers, otherwise they will be registered in both handlers.