Unit of Work Multiple Events

Hello all,

I am trying to migrate some services which used Axon 2 to Axon 4, and one change I noticed between the two was that the DefaultUnitOfWork now requires a Message in its constructor. I was wondering how it would work, because I thought the UnitOfWork could be used to commit multiple events at once, and was wondering why in Axon 3 and onwards it requires a Message type in the constructor. Is there something I am not getting about the Unit of Work?


Hi Paul,

I believe we had more direct contact already, but for continuity for other readers of the forum, I’ll post a reply here as well.

The Unit of Work is intended to wrap every message type in Axon and as such this is now enforced through generics by expecting a Message as input.

To deal with several messages under the initial Unit of Work, a nesting approach has been taken.
Thus, there is a parent Unit Of Work with child Unit-of-Work’s (from here on UoW) under it, which can expand as far as necessary.

As such, the DefaultUnitOfWork only takes in a single message to simplify the thought process around it.
If you’d then dispatch another message, which internally means you’ll initiate a new UoW, it’s the internals of the AbstractUnitOfWork that ensure that this new message is nested under the Current Unit Of Work.

Additionally, to start dealing with streams of events, as the Event Processor implementation from Axon 3 onward do, there is the notion of a BatchingUnitOfWork.
This takes in a list of Message instead of a single Message, potentially the thing you are looking for.

So, I have given quite some background here, which I assume will resolve your concerns.
But, I think it would be beneficial for any attendees of this forum if you could share the exact use case you are having.

Hope this helps you out Paul!