Reputation: 2523
I am curious to find out how you guys are incorporating meta data about command/event messages in a cqrs solution. For example, I want to know who, when, which host, etc. generated the command. I don't want to put these into message itself.
Say in a web app, user created a shopping cart CreateShoppingCart { CartID, UserID }
. Then added items to it, AddItem { CartID, ItemID, Amount, etc }
. I want to record exacty when the used clicked the "Add To Cart" button.
Dictionary<string, object> Headers { get;
set; }
property. That property could be in a BaseMessage class.LogCommandDetails { CommandID: 'id of AddItem command', DateTime, Some other meta data }
. When this comamnd is handled, I can update the projection of ItemAdded event and add this data into the projection.What are your thoughts?
Thanks
Upvotes: 2
Views: 1002
Reputation: 37719
Typically this information is stored in message headers, which is option 2. This is exactly what message headers are for. Note, there is a subtle difference between a message from perspective of a messaging framework and a message in your domain which is the body of the message in a messaging framework.
However, it can be difficult to discern what is data and what is metadata. I run into this issue with dates, among other things. For example, is a timestamp associated with an event metadata or proper domain data? What if the timestamp is required for execution of certain business logic? In your example, do you need to record the date for reporting or audit purposes, or is the date needed for the domain to function? In the former case, use headers, in the latter, place the date in the message body.
Upvotes: 2