Replaying events using snapshot strategy


I’m able to create snapshots every X events. After deleting token and entire database the axon starts to replaying events (I’m doing this way because i’m testing this). What I’m seeing is that all events (from start to past) is being replayed generating a large amount of events. How can I replay events considering the snaphost strategy ?



Event 1
Event 2
Event 3
----------------- Snapshot (every 3 events)
Event 4
Event 5

Replaying Events

Event 4
Event 5


As you said you delete the tokens, I guess this implies that you’re using a TrackingEventProcessor to feed events to one or more handlers.

The event processors are (AFAIK) not aware of snapshots, as a snapshot only makes sense when looking at an individual aggregate. Event processors deal with all messages across all aggregates. This is powerful as some read models which are being built from the TrackingEventProcessor may need more information than what’s available in a snapshot.

If you were to load the aggregate which has been snapshotted using a Repository, you should see that only the snapshot and subsequent events are read. When dispatching commands, Axon loads aggregates in this manner. You can manually do it by injecting the appropriate repo and calling Repository#load(String).

If you want to dig into the source code: