To read all events, the
readEvents(String) is not the right method.
As the Javadoc on that method points out, the function is meant to retrieve all the domain events for a given Aggregate.
To retrieve all the events in the store, you can use the
If you use
null as the given
TrackingToken, it will start reading from the beginning of the stream.
Another approach to reading all events from the store which does not require you to directly utilize the EventStore, is by building an Event Handler where the first parameter type is
The first parameter of an
@EventHandler annotated method is always the event payload, thus the event you’ve created in your code base.
Axon will always call the event handler function with the most specific implementation of a given event.
Thus, as all your events will eventually implement
Object, having a single Event Handler where the first parameter is Object will give you just that.
Note, that you should not perform this operation with a given Aggregate instance itself.
The Aggregate should be tasked with your business logic, thus handling a command which express some intent to be performed and publishing events as facts that the given operation occurred.
Retrieving the stream of all events to me does not sound like domain specific logic, more so infrastructure or delegation work.
Hope this sheds some light on the situation.