Concepts included in Axon Framework to grasp

Tram Ho

What is Axon Framework?



It can be understood that Axon framework is a modern framework that is popularly applied in microservices to build event-driven applications. Axon Framework is based on design principles like CQRS (Command Query Responsibility Segregation) and DDD (Domain Driven Design). In this article we will learn together how to apply it to our microservice system.

Axon Framework and Domain-Driven-Design

Axon Framework is heavily inspired by the Domain-Driven-Design idea. Therefore, there will be many concepts that readers will probably be familiar with if they have heard and known Domain-Driven-Design.

Let’s take a look at the following concepts:

Aggregate

Like DDD, Axon Framework also uses Aggregate as the core concept of the application. Aggregate is simply the Object you want to track and manage ( Domain Object ). To say the least, it embodies your whole application.

image.png

To make it easier to imagine, in a Spring Boot application using JPA, the @Entity annotation is the same as @Aggregation , with @Entity , Spring Boot will manage that class and for @Aggration , Axon will manage :vvvv

Domain-Events

Axon Framework also includes Domain-Events concepts. In other words, when Commands are executed by Aggregate, it will trigger one or more associated events . These events are called Domain-Events.

Aggregate handles events and relies on it to change its own state.

In the code below, you will see places tagged with @EventSourcingHandler . These functions will be called when the events associated with them occur.

Repository

In Domain Driven terminology, Repository is a very important concept. Repository is a component used to manage the Aggregate lifecycle, it is responsible for storing and retrieving Aggregates from a certain data store be it In-memory, JPA or JDBC, Mongo for example.

Message Driven Aspect of Axon Framework

Referring to Axon, we must mention the event-driven application, events expressed through another concept is Message . This message contains information related to payload, metadata bla bla… There are many types of Messages including:

Command

Command is a command used to change the state of the application. Note that these commands have not actually changed its state, just the intention to change

Event

Contrary to Command, when an event occurs, a certain state change has occurred. Specifically, it will appear after the commands have been processed successfully. These events are mainly used to send notifications where they need to be handled when the application state is changed.

Query

This third type of Message is simply a request to get some information, maybe information about the current state of the application.

In this article, I have introduced the concepts to grasp in Axon Framework. We’ll dig deeper by building Spring Boot applications with it.

See you in the next post!!!

Share the news now

Source : Viblo