Pergunta

So I've been reading about EventStore and NServiceBus and I like the idea of having a transactional log of my data that can help me build views based on that data.

What I don't understand right now is how to distinguish between an event that will write to your read storage and the same event which might trigger an email to get sent.

ex. Creating a customer

CreateUserCommand -> CreateUserCommandHandler -> CreatedUserEvent

Should I be using the CreatedUserEvent to trigger both my write to my data storage and sending an email to a user?

Foi útil?

Solução

In the last few years, Eric Evans has recognized an update to his DDD pattern: Domain Events (aka External Events concept).

Internal events in Event Sourcing patterns is what we've been focusing on, such as UserCreatedEvent in your example. Keep these explicit with an IEvent marker interface.

While IEvents are stull published on the bus, IDomainEvents are more notability for larger external-to-the-domain notifications that don't effect a state of an aggregate per say.

So...

CreateUser (ICommand)
 ^- CreateUserCommandHandler

UserCreated (IEvent)
 ^- UserCreatedEventHandler 

SendNewUserEmail (ICommand)
 ^- SendNewUserEmailCommandHandler

NewUserEmailSent (IDomainEvent)
 ^- UserRegistrationService or some other AC

I am still pretty new to event sourcing myself; but, I would guess that you can have the UserRegistrationService register on the bus to listen for the SendNewUserEmail ICommand.

Either way you go, I would concentrate on creating additional commands/events for sending an email and the email was sent. Then, later on you can view the transaction log as to when it was queued to send, how long it took to send, was there any retries in sending, how many was sent at the same time and did it effect time delays (datetime diffs) to show any bottlenecks?, install a queue for sending emails and break it out into a smaller independent service, etc etc.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top