Symfony, Broadway and the replay event

Note : This article is the translate of this article. I use Google Translate for help me to write in english. Please, if you read wrong phrase send me the correct by one comment.

On of the main advantages of EventSourcing is the replay event for build a new view database or sync the an old view.

Do have you ever wondered how to go about not send emails on events issued by the aggregates ?

In my case, the dilemma is rather important because many things are based on events. If they are replayed, all treatments are rerun.

In my project, I use Broadway (by QandidateLabs) for implementing the CQRS/ES.

For use the default event bus, you must tag any services with `broadway.domain.event_listener` and extend this class `Broadway\Processor\Processor`.
All services will be injected into the event bus by a compiler pass. The latter takes 3 arguments: the event bus service identifier, the tag used for get all services to inject her, and the interface name that services must implement to be injected.

You can reuse the code to add a new event bus without write more code.

3 steps for separate into new bus all services necessary for refresh view.

1) Add a new event bus

# src/Vendor/Bundle/NameBundle/Ressources/config/services.yml
          class: Broadway\EventHandling\SimpleEventBus
          lazy: true

2) Add new tag for all services to update the view. By exemple `mon_bundle.domain.event_listener`.
3) Run new compiler pass with new parameters

// src/Vendor/Bundle/NameBundle/NameBundle.php
use Broadway\Bundle\BroadwayBundle\DependencyInjection\RegisterBusSubscribersCompilerPass;
     new RegisterBusSubscribersCompilerPass(

This is a SOLID code.

Your event listener must also be. One listener one responsibility.

Finally, during the retransmission of events, simply send them on the bus dedicated to replay events to perform the update only the view.
That’s done! You can retransmit all the events to update the view without having to change the configuration of the production application to prevent the resend of the emails.

Get the source code on github.

Now you can share your experiences in the comments.

See also:

2 réflexions sur « Symfony, Broadway and the replay event »

  1. Hello Jean-Baptiste,

    Do you have any example code to show how this work ?

    I installed the broadway-demo test app but i don’t really understand how to reconstruct all the views based on this app.

    Thanx in advance !

    1. Hello Manel,

      This is a good question. You can retrieve the functional source code on my GitHub.

      I updated the post for add this link directly.

      I add a link on main page for replay all event for the selected aggregate. If you want, you can get the id, remove the view in database (table message) and call the replay URL with id.

      If you have another questions, tell me.


Les commentaires sont fermés.