EventStore and more than one unit of work?

560 views Asked by At

In the reply to few questions, Jonathan Oliver mentions using an AsynchronousCommitDispatcher to handle multiple unit of works.

I am still in the design stage of my project (and still learning CRQS and ES) and have a few questions:

  1. Would I create an AsynchronousCommitDispatcher for each aggregate root that will be affected by a domain event being raised?

  2. What happens if I have some sort of locking mechanism where the dispatched event cannot make a change to an aggregate root if it is locked by another user? Does AsynchronousCommitDispatcher retry if there is a lock?

  3. What if the system goes down before an domain event is handled? Unless I persist the fact that it has not been handled, wont it be lost?

  4. My initial understanding was that the types of Dispatchers were for messaging across the wire or for updating the read model. Here we are using it to update another aggregate root. I this correct?

TIA

JD

1

There are 1 answers

2
Jonathan Oliver On BEST ANSWER

The commit dispatchers are all about pushing events onto the wire after everything has been completely successfully. No, you don't need more than one dispatcher for a given endpoint. The AsyncCommitScheduler (which uses a dispatcher) is multi-threaded and can dispatch more than one event at a time.

A dispatcher is not about handling an incoming message--that's what your message handlers are for. The dispatcher just sends once everything is complete.

Yes dispatchers can help update read models, but not in the way you think. Instead, the dispatchers just push the messages into your messaging framework (MSMQ, RabbitMQ, or, at a higher level, NServiceBus/MassTransit). Then once a message is received at your view models, you update your view model tables accordingly.