Event handlers with parameter of type UnitOfWork are no longer handled by tracking event handlers since Axon 3.1


We are currently upgrading an application to Axon 3.1 (from 3.0). We have a number of event handlers that have an argument of type UnitOfWork (we want to publish a message over a web socket after commit). The event handlers are assigned to tracking event processors. Before Axon 3.1, the event handlers were called but since 3.1 they are not. After some (ok, honestly, quite a bit of :)) debugging, I found out that the org.axonframework.commandhandling.CurrentUnitOfWorkParameterResolverFactory indicates a mismatch with the event message because CurrentUnitOfWork.isStarted() evaluates to false.

Not sure if this is an issue, or just intended behavior. The UnitOfWork is not listed in the docs as a supported parameter type, but is was in fact working in Axon 3.0. It would be very nice if we could keep using is in tracked event handlers.

Curious what you guys think, so any feedback is much appreciated

Best regards
Martijn van der Woud

Ok sometimes it helps to write questions down to come up with an answer by yourself :slight_smile:
Just realized I can use CurrentUnitOfWork.get() inside the event handler. Apparently, by the time the handler gets invoked, the UOW is in fact started, just not yet when org.axonframework.eventhandling.AbstractEventProcessor#canHandle is invoked

Hi Martijn,

There were some logic changes in the TrackingEventProcessor to adjust the batch of events being handled by it’s Event Listeners.

Since 3.1, it will first check if there are any event handling functions which are interested in that event.

If there are none, it will remove that event from the batch, which should generate a more efficient approach to calling the handlers.
However, the check whether there’s a handler for an event also incorporates the check ParameterResolvers do to check if it should wire parameters for that event handling function.

As you might have guessed, there’s an CurrentUnitOfWorkParameterResolver which resolves the UnitOfWork as a parameter in your event handling functions.
The check which was performed in the CurrentUnitOfWorkParameterResolver however investigated if there was a CurrentUnitOfWorkStarted, which through the above described scenario wasn’t the case anymore in TrackingEventProcessors.
This PR however solves the issue you’ve found, which is part of Axon Framework version 3.1.2.

And added to that, we’ve just released 3.1.2, so you can already use that fix in your project :slight_smile:

Hope this helps!


Hey, that’s great Steven, thanks!