14 Eventsourcing Cqrs
14 Eventsourcing Cqrs
In the micro-lab-docs folder given to you, observe that there is axonserver-4.3.1.jar given to you.
Open cmd prompt, cd to micro-lab-docs folder and execute the following command to start axon
server
Open browser and give request to http://localhost:8024 and see the UI of Axon Server.
Click on Commands tab on left menu and observe that there are no registered commands.
Also, we are using H2 Database and swagger. Observe that H2 and Swagger dependencies are also
added in pom.xml
@Aggregate annotation tells Axon that this entity will be managed by Axon. Basically, this is similar to
@Entity annotation available with JPA
@AggregateIdentifier annotation is used for the identifying a particular instance of the Aggregate.
Every command which is associated with an Aggregate must have that aggregate’s identifier. So, this
BaseCommand will be made as a super class for all commands
Open CreateAccountCommnad.java, CreditMoneyCommand.java, DebitMoneyComand.java and observe
them
Open BaseEvent.java in com.way2learnonline.events and observe it. Observe all the other Event classes
present in that package.
Service Layer
Controllers
Go go the axon server UI on http://localhost:8024 and click on Coomands link in left menu.
see that the commands are registered and all counts are 0
Testing
After making requests, events will be stored in the event store managed by axon server
Open pom.xml and observe that axon server dependencies are added just like in step2
Open AccountAggregate.java and observe that it has only EventSourcing Handlers only with out
command handlers
Open AccountQueryServiceImpl and observe how it is querying eventStore to read events and
querying account table.
Now start this application from boot dashboard and open the swagger ui at
http://localhost:8081/swagger-ui.html
Use swagger ui to query for account by account number and also list all the events from eventstore
for a particular account.