I see.
I can think of some ways to introduce this on the payload:
- Explicit fields on the payload itself.
=> This is easy until you get 100s of messages and explosion of right to left copying in order to ensure metadata is passed on.
- Explicit fields on some base trait.
=> Hard to maintain and change, pollutes payload with one context to rule 'em all.
- Headers field on a base trait that payload extends.
=> Flexible, not type safe and needs some sort of extractors. This is similar to having it on Message, but is brittle when doing stuff like msg.copy(evt = differentPayload).
You have to remember doing the right sort of gymnastics all over the place.
and then there is the option of:
- Envelope that contains headers field and payload
=> This means that we need to maintain our own receiver of sorts that wraps / unwraps and can drift from how eventsourced itself works.
One additional level of indirection is a bit awkward in my book.
We have 100s of commands and events in just *one* of our bounded contexts and this is a pretty common requirement.
That is why I was thinking about how eventsourced itself can make life easier for us developers.
When you guys say that you keep that information on the payload itself, what kind of data is this and is it in a header field?