One of key benefits of a message-based systems is the loose coupling between participants; the message sender and recipient make no (or few) assumptions about each other's identity. If a message recipient retrieves a message from a message channel, it generally does not know nor care which application put the message on the channel. The message is by definition self-contained and is not associated with a specific sender. This is one of the architectural strengths of message-based systems.
However, the same property can make debugging and analyzing dependencies very difficult. If we are not sure where a message goes, how can we assess the impact of a change in the message format? Likewise, if we don't know which application published a message it is difficult to correct a problem with the message.
How can we effectively analyze and debug the flow of messages in a loosely coupled system?
Therefore, attach a Message History to the message. The Message History is a list of all applications that the message passed through since its origination.
The Message History maintains a list of all components that the message passed through. Every component that processes the message (including the originator) adds one entry to the list. The Message History should be part of the message header because it contains system-specific control information. Keeping this information in the header separates it from the message body that contains application specific data.
Not every message that a component publishes is the result of a single message. For example,an Aggregator publishes a single message that carries information collected from multiple messages, each of which could have its own history. If we want to represent this scenario in the Message History, we have two choices. If we want to track the complete history we can enhance the Message History to be stored as a hierarchical tree structure. Because of the recursive nature of a tree structure we can store multiple message histories under a single 'node'. Alternatively, we can keep a simple list and only keep the history of one incoming message. This can work well if one incoming message is more important to the result than other, auxiliary messages.
... Read the entire pattern in the book Enterprise Integration Patterns
Related patterns:
Aggregator, Control Bus, Message Router, Message Store, Process Manager, Publish-Subscribe Channel, Recipient List