Message Tracking
Tracking messages in your system can be useful to analyze what the cause of a message was. There are several ways to track messages in your system. You can correlate messages to each other with a Correlation Data Provider or log the messages being handled and dispatched.
Correlation data
The framework provides the CorrelationDataProvider
, as described here.
This interface and its implementations provide you the means to populate the meta-data of a message based on the message
that is currently being handled.
For instance, you could use this to store the command that triggered the event in the metadata of the event itself,
allowing you to track the cause of it.
Axon Framework provides a MessageOriginProvider
provider out of the box,
which adds a trace-id
and correlation-id
to all messages.
The trace-id
is the same over all messages that are triggered because of the same origin,
while correlation-id
contains the message identifier of the previous message.
We can see the effect of this in the following table.
Message identifier |
Type |
|
|
1 |
Command |
- |
- |
2 |
Event |
8231323 |
|
1 |
3 |
Command |
|
8231323 |
2 |
4 |
|
Event |
8231323 |
3 |
Check out the message correlation page
to find out more about the MessageOriginProvider
.
Interceptor logging
You can also track the flow of messages through your application using logging.
You can leverage Handler- and DispatchInterceptors to achieve this.
The LoggingInterceptor
is provided out-of-the-box solution to log any type of message to SLF4J,
but also provides a simple overridable template to set up your own desired logging format.