replacement for EventProcessingMonitor in axon 3

119 views
Skip to first unread message

Sara Pellegrini

unread,
Nov 25, 2016, 12:58:41 PM11/25/16
to Axon Framework Users
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




René de Waele

unread,
Nov 25, 2016, 2:21:17 PM11/25/16
to axonfr...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

René de Waele

unread,
Nov 25, 2016, 2:23:46 PM11/25/16
to axonfr...@googlegroups.com
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!

Sara Pellegrini

unread,
Nov 27, 2016, 5:35:55 AM11/27/16
to Axon Framework Users
Hi René,
can you give me an example of both your solutions?

René de Waele

unread,
Nov 28, 2016, 5:35:23 AM11/28/16
to axonfr...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages