jeudi 7 mars 2019

How to aggregate domain events to take a single action in a single event subscriber?

Imagine that I am creating and persisting multiple new aggregates. As per the domain event pattern, each one generates a domain event entity.created. One business rule says that in this process to create these entities, if there is a problem with some of them, send an email to a manager with a list of the problematic entities. So many entities changing will result in a single output.

I was thinking to have a new "emailer" event subscriber subscribe to the entity.created event, and add each event that contains a problematic entity to a list. Then "somehow" (that's the question) once all the events are added to the list, loop through them an put together a single email with the entity IDs. But something just seems wrong about this whole approach.

  1. Is the method I described good? And if so, how should I trigger "no more offers to create, send the email now" part?
  2. Should I scrap the usage of domain events and just have the service that persists the entities send the email?

Aucun commentaire:

Enregistrer un commentaire