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
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
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.