Event handling, UoW and transactions


i’ve a question regarding view model consistency for the case that a single command will apply multiple events. All the view model updates should be transactionally processed then and i wonder how to achieve this.
I read http://www.axonframework.org/docs/2.0/single.html#binding-uow-to-tx but i don’t understand how this can be used here because the transaction manager handles a global transaction as where the view model event handlers might receive events related to different aggregate instances, isn’t it? What i would expect is a concept of a transaction related to a specific aggregate instance but probably i’ve misunderstood something. Could someone explain please?



Hi Marcus,

there are two forces at play, which should not be confused. When a command is executed, it may generate several events. These events are stored an published in a single unit of work/transaction.
When using the simple event bus, publishing events also means processing them. So events are processed in the transaction that created them. Since a single command (generally) targets a single aggregate, this transaction is bound to the activity of a single aggregate.

When using an asynchronous event dispatch mechanism, the events are handled in a separate transaction. How you want to deal with transactions here is completely independent from the command transactions. This means you can process events from multiple aggregates in the same transaction, or any other way you like.

Hope this clarifies things a bit.