I have simple case when I have thousands of small events and some event handler that counts them.
The way how I see:
- TrackingEventProcessor takes N (batchSize) events, creates and starts UoW, sends batch to EventHandler, commits UoW
- EventHandler subscribes to UoW on each Start to create a counter variable, receives events one by one (or event better as a list), increases counter and on UoW commit, stores value in some DB.
I use axon without Sprint Boot so I had to configure axon via DefaultConfigurer. I managed to set batch size, But I have no Idea how I can subscribe to UoW notifications.
In documentation (https://docs.axoniq.io/reference-guide/configuring-infrastructure-components/messaging-concepts/unit-of-work) I found that it is possible to get current UoW by calling
But in TrackingEventProcessor I found this piece of code:
// TrackingEventProcessor.java:391 UnitOfWork<? extends EventMessage<?>> unitOfWork = new BatchingUnitOfWork<>(batch); unitOfWork.attachTransaction(transactionManager); unitOfWork.resources().put(segmentIdResourceKey, segment.getSegmentId()); unitOfWork.resources().put(lastTokenResourceKey, finalLastToken); processInUnitOfWork(batch, unitOfWork, processingSegments);
As far as I can see it means that each batch has brand new UoW each time. So it makes impossible to subscribe on UoW notifications once via CurrentUnitOfWork.get()
Could someone share his experience with processing events in batches?
I’m lost a bit.