Silk0vsky
Silk0vsky

Reputation: 1032

How to event source entire datastore with axon?

I'm trying to design architecture based on CQRS principles. One of the requirements is the ability to introduce over time new projections for query subsystem based on existed event log. To do this I need the ability to iterate over all event records stored in data storage. Is it possible with axon?

Upvotes: 3

Views: 168

Answers (1)

Steven
Steven

Reputation: 7275

This is definitely possible in Axon. The keyword to look for in this case is the TrackingEventProcessor.

The EventProcessors in Axon are in charge of dealing with the technical aspects of delivering events to the Event Handlers you are writing. The TrackingEventProcessor does this on it's own accord by retrieving a stream of events from the EventStore. As your application can start/stop/pause/etc, the TrackingEventProcessor should also be stoppable. Consequently though, you'd want your TrackingEventProcessor to start again from the point it stopped the last time.

It thus has to keep track off where it is in regards to handling events from the Event stream. That 'keeping track off' is done by keeping a TrackingToken, which contain the index (and depending on the implementation of the TrackingToken also other information) of the last event is has handled.

This token can be set at any point in time in respect to your event stream. It will thus allow you to initiate a replay/reset for a giving Query Model which it updates. Or, if you'd need to source your query model every time on start up, you could simply keep the TrackingToken in memory only. This will ensure that at start up it will begin reading events from the beginning of time.

For more information on Event Processor in Axon, I recommend the reference guide.

Side note: All this put aside though, I would like to point out that the hard part in Event Sourcing does not lie with the Query side of your application. That part is always hydrated from the entire stream of events. Event sourcing the command model is however something different entirely. To that end, Axon provides the EventSourcingRepository to store your Aggregates with.

Upvotes: 3

Related Questions