Putting everything together
The final piece of our test application is a CQRS framework to load up the aggregate, process incoming commands,
persist the events and apply them to our queries. This is provided by a CqrsFramework
component which takes an
EventStore
and a vector of boxed Query
s.
Wiring this all up and firing two commands:
To run the test we should ensure that rust does not consume our output.
cargo test -- --nocapture
Which should give us output something like this:
running 1 test
loading: 0 events for aggregate ID 'aggregate-instance-A'
storing: 1 new events for aggregate ID 'aggregate-instance-A'
aggregate-instance-A-1
{
"CustomerDepositedMoney": {
"amount": 1000.0,
"balance": 1000.0
}
}
loading: 1 events for aggregate ID 'aggregate-instance-A'
storing: 1 new events for aggregate ID 'aggregate-instance-A'
aggregate-instance-A-2
{
"CustomerWroteCheck": {
"check_number": "1137",
"amount": 236.15,
"balance": 763.85
}
}
Here we see the output from our SimpleLoggingQuery
along with some logging from the MemStore
which is just what we hoped
for.
This shows our entire framework working including loading events, rebuilding the aggregate, processing commands and distributing events to a query. Next, we will move on to actually using this in an application.