I want to get the current state of an Aggregate entry (taking into consideration all events and snapshots that has happened to it) without tracking the changes to that Aggregate via @Entity (i.e. without tracking the changes to that aggregate via sql update statements).
I am new to Axon and my experience with CQRS has only been a few days of using Lagom. So I may be off with my understanding of some of the concepts. But here’s my understanding
An Aggregate can accept Commands and those Commands basically represent what you can do with that Aggregate. And Events are records/logs of what happened to that Aggregate. And when persisting the Aggregate into the database, instead of persisting the changes as update statements into the database, Events are the ones that are persisted instead. That way, you can rebuild the state of the Aggregate by ‘replaying’ the events.
So for example, let’s say we have a InventoryItem entity (with an id, name, quantity), if the following things are to happen
- Added 10 new TShirts InventoryItem
- Update quantity to 8
- Update quantity to 3
- Update quantity to 13
- Update name to T-Shirts
In a traditional database approach, this would look like this
insert into inventory_item (id, name, quantity) values (1, “TShirts”, 10);
update inventory_item set quantity = 8 where id = 1;
update inventory_item set quantity = 3 where id = 1;
update inventory_item set quantity = 13 where id = 1;
update inventory_item set name = “T-Shirts” where id = 1;
And then if you want to query the current state of that item, you would do
select id, name, quantity from inventory_item where id = 1;
Now in a CQRS system, it would look something like this instead
AddNewInventoryItem - name = TShirts, quantity = 10
UpdateQuantityOfInventoryItem - quantity = 8
UpdateQuantityOfInventoryItem - quantity = 3
UpdateQuantityOfInventoryItem - quantity = 13
UpdateNameOfInventoryItem - name = “T-Shirts”
And then if you want to query the current state of that item, you would replay all those events which eventually result to an InventoryItem of name “T-Shirts” and quantity 13.
In Axon, I believe Events are stored in an EventStore. And this can be in memory, or backed by RDBMs or Mongo or whatever.
However, I cant seem to figure out how to query the current state of an Aggregate (through “event replaying”).
Most examples, make the aggregate @Entity which means not only are Events being stored, but changes to the Aggregate are also being tracked via sql update statements.
Am I missing something? Can anybody recommend a documentation page / sample code base where I can get the current state of an aggregate without tracking the changes to that Aggregate with @Entity (or sql update statements) ?