AXON is an Open-Source Framework for event-driven microservices and domain-driven design. It is a Java Framework that provides developers with access to repositories, implementations of key components including aggregates, commands, and events, and implementations of the CQRS architectural pattern. Architecture principles such as Domain Driven Design and CQRS underpin the framework.
So what’s the requirement for Axon or the need for axon?
CQRS is fundamentally different from layered architecture, which makes it difficult for developers to navigate this architecture.
The Axon Framework is designed to support developers in applying the CQRS/DDD and Event Sourcing architectural pattern. It helps developers create easily scalable and maintainable applications by providing implementations of some basic building blocks such as aggregates, repositories, and the event bus (mechanism for sending events)
Axon also provides annotation support that can be used to create aggregates and event listeners without using specific Axon logic. This allows developers to focus on business logic instead of plumbing and helps you make it easier to test code in isolation.
in the above picture, we can clearly see that the command side and query side are clearly separate.
Axon separates Messages in roughly three categories:
Commands: A component’s desire to change something in the system. Aimed at one target and can provide an answer.
Queries: Represent a need for information. It can route to one or more destinations depending on the shipping strategy.
Events: Represent the occurrence of something that may be important to other components. Events are published to all interested constituents and do not provide any form of return.
Advantages of Axon Framework:
- Unified Distributed Messaging Solution: One of the main reasons why it is so famous is sending commands, events, and queries in a single application is very simple with the provided message buses.
- Event Processing Enhancements: Updating your views and search options based on the latest events passing through your system becomes natural when you use it.
- Real-time Event Streaming: Although the trace event processor is pretty neat, there was still one performance impact that can be resolved.
- Aggregate Modeling Improvements: We all know Axon is a great stepping stone to DDD.
- Multi-Context Support: When implementing DDD, the concept of bounded contexts will surely cross your path
Relationship between Axon and Kafka
So, Axon provides application-level support for domain modeling and event sourcing, as well as command, event, and query routing, while Kafka shines as an event streaming platform.
Some annotations used in Axon Framework:
- Aggregate: An aggregate is an isolated tree of entities, capable of handling commands. In the Axon framework, aggregates can be implemented using JPA or Event Sourcing, depending upon our preference.
- @TargetAggregateIdentifier: annotation tells Axon that the annotated field is an id of a given aggregate to which the command should be targeted.
- @AggregateIdentifier: As the aggregation will process commands that target a specific instance of the aggregation, so to specify an identifier we need AggregateIdentifier annotation.
- @CommandHandler: This annotation is used to tell the framework that the given function is able to handle commands,
- @EventSourcinghandler: It marks a method in an Aggregate as a handler for Events generated by that aggregate. Let’s suppose you have an “OrderCreatedEvent” event that is handled in @eventsourcinghandler to set the orderId and orderConfirmed status of the order summary.
there are many more.
Now, start setting up the 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 from here: https://axoniq.io/download
This package contains:
- Axon Framework Binaries
- Axon Server SE
- Gift card sample application
- Getting started guide
Once the download is completed, follow the steps below to run it:
- Unzip AxonQuickStart-VERSION.zip
- Run the Axon Server:
$ java -jar AxonServer/axonserver-VERSION.jar
- View the Axon Server web dashboard here: http://localhost:8024/
- Run the demo application:
$ cd giftcard-demo && ./mvnw spring-boot:run
- Open the Demo application here: http://localhost:8080/
In this blog, we learned about the basics of the Axon framework, its advantages, its dependency, and some important annotations used in it. We will be covering this in more depth in our upcoming blogs. read more here about it, for other great blogs, must visit this.