Reputation: 220
I am using Axon Framework without Axon Server and with Spring Boot auto configuration. I have an H2 database, using the Spring auto configuration.
It seem like the EventStore
API only provide the EventStore#readEvents(String aggregateId)
method, to read all events for a specific aggregate.
However, I would like to read all events, fron all aggregates.
How can I achieve this?
And secondly, I don't want to serialize the data in the payload, I want to store it in JSON, how can I do that?
Thanks.
Upvotes: 1
Views: 2400
Reputation: 7275
The EventStore
interface itself indeed only contains methods to read events for a given Aggregate.
That interface however implements the StreamableMessageSource
interface (which you can find here).
Through this interface, the EventStore
provides you the openStream(TrackingToken)
method. The TrackingToken
specifies at which point in the stream you want to start.
As a short cut, if you provide null
as the TrackingToken
, the stream will open at the beginning of time (for said event stream of course).
Note though, that I would typically suggest against querying the EventStore
directly.
Axon provides a perfectly fine annotation based approach to handling events, by drafting up an @EventHandler
annotated method in an Event Handler class you register to the store (something which is done automatically for you when using Spring Boot auto configuration).
As a short hand to read all events in a single Event Handling Function, you can do the following:
@EventHandler
public void on(Object event) {
// Perform event handling logic
}
In this snippet, I am performing somewhat of a trick.
Axon will by default provide an Event to the most specific implementation of said event.
As everything in Java implements Object
, simply having a single Event Handler where the first parameter (note that the first parameter is always the Event payload) is of type Object
will do the trick.
Now for the last question you've posted (I would suggest to make separate question for this in the future to keep focus on Stack Overflow):
And secondly, I don't want to serialize the data in the payload, I want to store it in JSON, how can I do that?
Do you mean you want to handle the event as JSON in an Event Handler?
Or, that you want to retrieve a stream of JSON from the EventStore
directly?
Note that it's impossible to store the objects as is, so serialization will always take place.
If it's disabling deserialization, then I can tell you that you'll have to query the actual database yourself for this, or heavily customize the EventStorageEngine
(the storage engine is what the EventStore
uses to retrieve events from your database).
The AxonIQ team is thinking of adding just such a feature, but I can assure you that this hasn't been implemented yet.
Hope this clarifies your options @polosoft!
Upvotes: 2