HappYness-Project / Happy-EventSourcing

Event sourcing
10 stars 1 forks source link

Dispatching domain events implementation #7

Closed hyunbin7303 closed 1 year ago

hyunbin7303 commented 2 years ago

Document from the MS :https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/domain-events-design-implementation

Use domain events to explicitly implement side effects of changes within your domain.

Either domain and integration events are the same stuff: notifying that just happened, but their implementation may be different. Domain events are just messages which pushed to a domain event dispatcher, which could be implemented as an in-memory mediator based on an IoC container or any other method.

The purpose of integration events is to propagate committed transactions and updates to additional subsystems, whether they are other microservices, bounded contexts or even external applications. So, they should occur only if the entity is successfully persisted, otherwise it's as if the entire operation never happened.

Implementation plan

There are usually three portions involved.

  1. Event Producer
  2. Event Consumer
  3. Event Dispatcher

Event producer is a domain entity. Each entity can generate one or more domain events during a business transaction.

Event dispatcher picks up all domain events generated by each entity and dispatches them to event consumers.

Event consumers are classes that subscribe to domain events in advance.

hyunbin7303 commented 2 years ago

23 #24