Replay events - only for a single aggregate

I finally managed to replay events (I am using event sourcing and a read model) for a @ProcessingGroup. I am using axon framework V4.1 .

But what I really want to do is rebuild the read model only for one single aggregate instance (which I know by id).

So my question ist:
Is it possible to replay events for only one single aggregate?

Thanks!

Sebastian

I’d really like to know too.
If you ever figured out how to do this please share. I want to use this to be able to rebuild the state at a certain timestamp. Documentation says this is one of the benefits of event sourcing, but doesn’t show how to do it.

Hello,

The most straightforward way is to use EventStore and read the events for specific aggregate id.

package org.axonframework.eventsourcing.eventstore;

/**
 * Open an event stream containing all domain events belonging to the given {@code aggregateIdentifier}.
 * <p>
 * The returned stream is <em>finite</em>, ending with the last known event of the aggregate. If the event store
 * holds no events of the given aggregate an empty stream is returned.

Hi Robert,

thanks for your reply.

But what do I do after I have read the events for my aggregate?
Can I “manually” replay them?

Thanks,
Sebastian

If want to replay the projection for specific aggregate using built in axon ‘processor’ thing. (Ie, resetting a token), you would need to create projection handler for every aggregate. So yes, i do not think that this is currently supported with axon to ‘filter’ specific events by their aggregate id when replaying a stream of events to project some data.

EDIT:

Sorry, by aggregate I’ve meant aggregate instance.

Hi,
Thank you for pointing me towards the EventStore#readEvents method.
My query handler was able to use the axon AnnotationEventHandlerAdapter to call my own object with @EventHandler methods to play back the events for a specific object and rebuild a state I’m interested in.
I can also filter the event stream based on timestamps, so I can do temporal queries.
I have noticed that calling readEvents without a sequence number will use snapshots. And passing ‘0’ as sequence number will play back all events. So that’s very useful.
I hope this extra information is useful to Sebastian.

Thanks again!

Ok thanks for all the feedback.

I managed to load the events for the one aggregate I wanted to update und also managed to replay them manually with my “Updater” class (the class with the “@ProcessingGroup” annotation). For every existing event type I had to an “if instance of XXEvent” and then call the appropriate method. Works but it’s not very nice. I might work out a more elegant solution.