replacement for EventProcessingMonitor in axon 3

Hi all,

we are migrating our web application from axon2.4 to axon3.

We use WebSocket to send Events from server to the client and in Axon2.4 we used an EventProcessingMonitor subscribed to a cluster because it is notified after the events are processed by handlers.

In Axon3 we need to find a similar solution to implement the same functionality.
We found two possible candidates in MessageMonitor or MessageHandlerInterceptor but we have not been able to understand how to use them.

Thanks to anyone who can give help

Hi,

In Axon 3 you can do the same by attaching a listener to the Unit of Work in your event handler. Once the Unit of Work goes into the PrepareCommit phase all events in the publication batch have been processed. That’s the case because the events are processed in a BatchingUnitOfWork, i.e. a UnitOfWork that processes a batch of events at once. After all events have been handled by event listeners registered with the event processor it will go into the PrepareCommit phase.

Best,
Rene

Oh and obviously you could also attach a MessageHandlerInterceptor to the processor to achieve the same thing. Just make sure you only attach the listener to each unit of work once!

Hi René,
can you give me an example of both your solutions?

Hi,

This is what I was thinking about (warning: pseudo code):

@EventHandler
void on(SomeEvent event) {
UnitOfWork<?> uow = CurrentUnitWork.get();
uow.getOrComputeResource(this.toString(), s -> {
uow.afterCommit(u -> updateClient());
return new Object();
})
}

Looking at the above code sample there seems to be a lot of room for improvement :). One option that is being considered is to add an event handler parameter that lets you know if an event was at the end of a batch, e.g.:

@EventHandler
void on(SomeEvent event, @LastInBatch boolean lastInBatch) {
if (lastInBatch) {
updateClient();
}
}

This will probably make it in the Axon 3.0 final release (but no promises :p).

Regards,
Rene