Count of Events in Unit of Work

I have an EventListener adapter that wraps events in an envelope and sends them to a Spring Integration channel. Is there some method to obtain that this event is “x of y” within the total events being published from the unit of work?

I looked at the auditing command handler interceptor however there does not appear to be a way to go back and update metadata from previously applied events. Or should I publish non-domain events before and after in my command handler?

Thanks,
Randy.

Hi Randy,

currently, the API’s don’t allow you to modify any events after they have been registered. At that moment in time, it’s also not possible to know whether an event is the last. It is, however, possible to know the sequence number of the events. You can keep state in your listener. Simply maintain a Map (take one from the java util concurrent package) of UnitOfWork to Integer. The integer can be the last sequence number assigned to an event. On the cleanup of a UnitOfWork, you can delete the entry from the map.

The only issue is that you don’t know what the last event is. At least, not at the point where you are processing the events. For that, you could register a non-domain event (if really necessary) that marks the end of a series of events. Meanwhile, I’ll have a look at how to make this easier in future versions of Axon.

Cheers,

Allard