Tracking messages in your system can be very 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.
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
MessageOriginProviderprovider out of the box, which adds a
correlation-idto all messages. The
trace-idis the same over all messages that are triggered because of the same origin, while
correlation-idcontains the message identifier of the previous message. We can see the effect of this in the following table.
You can also track the flow of messages through your application using logging. You can leverage Hander- and DispatchInterceptors to achieve this. The
LoggingInterceptoris rovided 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.