0% found this document useful (0 votes)
58 views3 pages

14 Eventsourcing Cqrs

This document provides instructions for implementing event sourcing and CQRS patterns using Axon framework. It describes starting the Axon server, developing the command and query applications separately. For the command application, it explains adding dependencies, configuring the aggregate, commands, events and services. For the query application, it discusses event sourcing handlers, querying the event store and database to retrieve and serve queries. Testing is done using Swagger to create, update and delete accounts, and observe commands and events in Axon server and retrieve account data from the query application.

Uploaded by

vignesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views3 pages

14 Eventsourcing Cqrs

This document provides instructions for implementing event sourcing and CQRS patterns using Axon framework. It describes starting the Axon server, developing the command and query applications separately. For the command application, it explains adding dependencies, configuring the aggregate, commands, events and services. For the query application, it discusses event sourcing handlers, querying the event store and database to retrieve and serve queries. Testing is done using Swagger to create, update and delete accounts, and observe commands and events in Axon server and retrieve account data from the query application.

Uploaded by

vignesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

LAB- Implementing EventSourcing

and CQRS using Axon


Step1-    Developing a Command Application

In this Step, you will be working on 01-es-cqrs-commandapp-start project

Firstly, Let us start Axon Server.

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

java –jar axonserver-4.3.1.jar

Axon server start on 8024 port.

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.

Open pom.xml and complete TODO-1

Also, we are using H2 Database and swagger. Observe that H2 and Swagger dependencies are also
added in pom.xml

Open application.yml and observe the h2 related properties

@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.

Open AccountAggregate.java in com.way2learnonline.aggregates package and complete TODO-2


to TODO-5

Open BaseCommand.java in    com.way2learnonline.commands package and complete TODO-6

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

Open AccountCommandServiceImpl.java and complete TODO-7

Controllers

Open AccountCommandController and observe the request mappings and code

Open SwaggeConfig in    com.way2learnonline.config and observe the swagger Configuration

Run the main Class to start this application.

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

Open Swagger ui using http://localhost:8080/swagger-ui.html.

Make    a POST request to /bank-accounts through swagger to create an Account.

After making requests, events will be stored in the event store managed by axon server

Now go to axon server ui and observe the command counts.

Similarly, update and delete accounts through Swagger ui .

Step2-    Developing a Query Application

In this Step, you will be working on 01-es-cqrs-queryapp-start project

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 AxonConfig.java inside com.way2learnonline.config package and observe how


EvenSourcing Repository bean is configured

Open Account.java in com.way2learnonline.entities package and observe the JPA mappings

Open AccountRepository.java in com.way2learnonline.entities.repositories package and observe


that is is extending CrudRepository. So, an implementation will be generated automatically.

Open AccountEventHandler.java in com.way2learnonline,entities.handlers package and


observe how we have written EvenSourcing Handlers to handle Events on Account entity and
persist the accounts to database

Open AccountQueryServiceImpl and observe how it is querying eventStore to read events and
querying account table.

Open AccountQueryController.java and observe the request mappings and methods.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy