This content needs improvements
  • Design considerations needs details about messages characteristics
  • Usage section needs detailed examples
  • Reference section need more links to samples, source code, etc.
You are welcome to edit this page. You can search for and contribute to previous discussions about this page or start a new one .

Messages

This document provides information about the design, implementation, and intended usage of generic messaging in Axon Framework.

Design considerations

To allow components to communicate via messages, developers must represent those as Java objects. Axon Framework should provide means to construct such objects so it can use them to carry data from one component to another consistently across modules and deployment units. Below are the characteristics that every message has.

Uniquely identifiable

All messages are uniquely identifiable.

Serializable

Immutable

All messages are immutable. Updating a message mandates creating a new message based on the previous one, with extra information added. Immutability guarantees that messages are safe to use in a multi-threaded and distributed environment.

Implementation

In Axon Framework, a message is an immutable, serializable Java object implementing the Message interface.

Generic messaging class diagram
Figure 1. Generic messaging class diagram

When the communication is bidirectional, the response is an object that implements ResultMessage. A MessageDecorator abstract object allows for building more complex messages by wrapping existing message types.

Usage

Avoid using generic messages directly. Use higher-level abstractions such as Command Messages, Query Messages, or Event Messages instead.

Application developers don’t need to work directly with generic messages. The framework provides convenient higher-level abstractions for specific message types. It can also automatically construct the respective messages from domain-level objects, extract the payload of messages, and convert it to such domain-level objects.

That said, understanding the generic messaging design and object structure can significantly help during debugging or building custom extensions.

Reference

Javadoc
Source code