Replay events to create a temporary state of the past

Hello everyone,

A little bit of context:

I’m using Axon 3.3 in a SpringBoot 2 application. In this application, I have an event store and a projection repository (containing views). My event handlers update the views containing the data that I will query on later.

What I want to do:

I’d like to replay events of an aggregate until a given timestamp, so I can recreate those views at this timestamp. But I don’t want to keep those views.

Should I use the replay mode to recreate this view from the past, somehow using the given timestamp, in a temporary projection repository, query on it and delete it?

Any help on how to do that would be very much appreciated :slight_smile:

Thank you,

Thomas

Hi Thomas,

replaying will just trigger the creation of the specific view that you are replaying. In your case, you’d want to create a new view (similar to an existing one, and probably using existing models), but cap the event stream at a certain moment in time.

I think it is easiest to simply open a stream from the event store, filter events out if they’re not in the time you’re interested in, and apply them to an entity that you expect to report.
You can use the AnnotatedEventHandlerAdapter class to convert an @EventHandler annotated bean into something that can just handle event messages. These Event Messages come from the stream you’ve opened from the Event Store.

Hope this helps.
Cheers,

Allard

Hi Allard,

We’ll try that and let you how it went. The project is actually Open Sourced: https://github.com/voyages-sncf-technologies/hesperides

Thank you!

Hi Allard and Thomas,

Can you give us a more detailed example on how to “open a stream from the event store, filter events out if they’re not in the time you’re interested in, and apply them to an entity that you expect to report” as Allard mentioned as the suggested solution to this problem?

Thank you in advance,
Meletios

On the event store, simply:

eventStore.openStream(null /* or any token indicating the starting position*/)
Read from the stream, ignoring everything that doesn’t match your requirements.

Alternatively, use eventStore.readEvents(aggregateIdentifier), which gives you a stream on which you can use .filter(Predicate …) to filter out messages you don’t care about.

If you have an entity or a component with @EventHandler annotated methods, you can use the AnnotationEventHandlerAdapter to have these methods invoked based on the event messages received from the stream.

We have some ideas for providing “first level” support for this. For now, we just provide individual components to build these types of features.

Cheers,

Hello everyone,

We successfully managed to resolve this use case by, in fact, reading the event store to get the events we want to replay - as Allard suggested - and using a mock of the repository to avoid using a database to recreate the final state.

You wil find our solution here (the method to look for is onGetPlatformAtPointInTimeQuery).

Hats off to Lucas Cimon who thought about and implemented this solution.

Thomas