CQRS With Axon Tutorial – Part 1 – Introduction and Setup in Intellij

CQRS and Event Sourcing With Axon Framework Tutorial

In this series, I would teach you how to build a microservice that uses CQRS and Event Sourcing using the Axon Framework. In this Part 1, we would take an overview of the application we’ll build and the tools we’ll use.

I recommend you read up the concept of CQRS and Event Sourcing here.

  1. The Application we’ll Build
  2. What You’ll Learn in this Tutorial
  3. What We’ll Use in this Tutorial
  4. Setup in IntelliJ
  5. Setup Axon Server


1. The Application we’ll Build

We would build a gift card application step by step.

A gift card has a particular amount associated with it. I can be issued to someone. Then the recipient can redeem the amount. Also, the amount could be redeemed in parts. As such, when an amount is redeemed, the balance is updated/reduced.

Note: This demo was actually done in a webinar in 2018. However as of Axon Version 2019, the procedure in that webinar has many issues. Besides, the pace was such that beginners and intermediates in Axon Framework could not catch up.

So I have taken time to break it down to very simple, easy and clear bits. Besides, I’ll take time to explain the likely problems you’ll encounter and how to solve them


2. What You’ll Learn in this Tutorial
  • Axon Framework: for implementing CQRS and Event Sourcing
  • Axon Server: for managing Axon applications
  • AxonHub: used to connect among microservices
  • Vaadin: used for building robust User Interface
  • Kotlin: programming language that simplifies creating of classes
  • Kubernetes: we’ll deploy the application to Kubernetes cluster running on Google Cloud
  • Microservices: you can read it up here
  • Spring Profiles: enables mapping of your beans conditionally to profiles


3. What we’ll Use in this Tutorial

As mention we’ll use Axon Platform(Axon Framework + Axon Server), Vaadin, Kotlin.

In addition, we would use the following:

  • Intellij IDEA Community Edition (you can get it for free)
  • Spring Boot: for easily building web applications
  • Maven: dependency management

Prerequisite: You need to have Intellij installed.

Let’s dive right into Part 1!


4. Part 1 – Setup in Intellij

Follow the four steps below to set up the application

Step 1: Create a new Project in Intellij. Make sure to select Kotlin as the Language. You selection would be as shown below:

New Axon Project

Step 2: Click on Next and select the following dependencies:

Vaadin, H2 and Jpa. The screenshot is shown below. We’ll add more dependencies using the pom.xml file

Dependency Selection for Axon Project


Step 3: Click on Next, then Finish

Wait for a few second for the project setup to complete


Step 4: Create three packages inside the com.kindsonthegenius.gcwebinar package. The packages would be as follows

  • commands: package for the commands service
  • query: package for the query service
  • gui: package for the gui application

This three packages would eventually correspond to three microservices


5. Setup and Test Axon Server

We now need to set up Axon Server so we can monitor our services. To setup Axon Server, follow the steps below.

Step 1: Download Axon Server from here. (Its a zip file containing the axonserver jar file)

Step 2: Unzip the file into a local directory

Step 3: To start the server, open command prompt. Navigate to the axonserver jar file directory

Step 4: Run the command below:

java -jar axonserver.jar

The command starts the server

Step 5: Visit http://localhost:8024

You will see the AxonDashboard as shown below




At this point, you have completed the initial setup. Next, we would modify the pom.xml to add the needed dependencies, plugins and other modification. We’ll do this in Part 2