7

Axon Part 1: An Introduction to Axon Framework

 3 years ago
source link: https://blog.knoldus.com/axon-part-1-an-introduction-to-axon-framework/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Axon Part 1: An Introduction to Axon Framework
Knoldus Blog Audio
Reading Time: 3 minutes

This is the first part of an ongoing series of blogs explaining Axon Framework. This blog will help you get started with axon and get a basic understanding of the same.

Axon Header Image

Prerequisites

Understanding Axon requires a basic knowledge of a few Axon concepts. Those are:

  • Microservices
  • Command Query Responsibility Segregation(CQRS)
  • Commands, Events and Queries
  • Domain Driven Design(DDD)
  • Event Sourcing
  • SAGA Design Pattern

Introduction

Problem:

The demands of software projects is increasing at a very high pace. Which means projects and code bases are getting more complex with functionalities being constantly added and/or changed. At this point a seemingly easy-to-implement feature can require development teams to take apart an entire application. Also, today’s web applications target the audience of potentially billions of people, making scalability an absolute must requirement.

Solution:

The (Command Query Responsibility Segregation) CQRS pattern addresses these issues by drastically changing the design of the applications. Instead of separating logic into separate layers, logic is separated based on whether it is changing an application’s state or querying it. While executing commands, the query components update asynchronously using events. This mechanism of updates through events, is what makes this architecture so extensible, scalable and more maintainable.

So Why do we need Axon?

CQRS is fundamentally different than the layered-architecture which makes it difficult for developers to navigate around this architecture.

Axon Framework is designed to support developers to apply the CQRS/DDD architectural pattern and Event Sourcing.It helps developers build easily scalable and maintainable applications by providing implementations of some basic building blocks, such as Aggregates, repositories and event buses (the dispatching mechanism for events). 

Axon also provides annotation support, which can be used to build aggregates and event listeners without using Axon specific logic. This allows developers to focus on the business logic, instead of the plumbing, and helps you to make your code easier to test in isolation.

Axon Architecture

Axon Architecture

As we can see in the above image the command side and query side is clearly separate.

Axon separates Messages in roughly three categories:

Commands: Desire of a component to change something in the system. Routed to a single destination and may provide a response.

Queries: Represent a need for information. May route to one or more destinations depending on dispatch strategy.

Events: Represent the occurrence of something which might be of importance for other components. Events are published to any component interested and do not provide any form of return value.

Axon strongly recommends use of explicit message objects. Each Message in an Axon based application represents a specific Java Class in that application. This increases the writing overhead but in turn comes with a few advantages:

  • Use of explicit messages makes it easier to transparently distribute them to remote components.
  • Use of explicit messages is important in the long-term maintainability of an application.
  • Location Transparency: components that interact with each other don’t need to know the location of their counterpart.

Quick Start

Now, lets start setting up axon in our system.

Axon provides a Quick Start Toolkit for setting up Axon Framework and Axon Server SE (Standard Edition).

Note: It requires Java 8+ JRE in your system.

Download here: https://axoniq.io/download

This package contains:

  • Axon Framework Binaries
  • Axon Server SE
  • Gift card sample application
  • Getting started guide

After Downloading, follow the steps below to run it:

  • Unzip AxonQuickStart-VERSION.zip
  • Run the Axon Server:
$ java -jar AxonServer/axonserver-VERSION.jar
$ cd giftcard-demo && ./mvnw spring-boot:run

Note: If you’re on JAVA 8 please make the following changes:

  • In the extracted folder, open giftcard-demo\pom.xml with an editor or IDE whichever you prefer.
  • Change<java.version>11</java.version> to <java.version>1.8</java.version>
  • Find the maven-compiler-plugin block
  • Replace <release>${java.version}</release> with <source>${java.version}</source> <target>${java.version}</target>
  • Now it should run.

For detailed information please go through the Readme.md

You can visit axon official documentation here: https://docs.axoniq.io/reference-guide/

This introduction guide will help you get started with Axon. To Know more, please visit Knoldus Blogs for the next part in this series.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK