Working with Metadata
Working with event metadata in Event Sourcing
All Events may contain additional Metadata. This is especially useful for storing information that are not required for Command to be handled, yet are important for auditing and projecting purposes.
Metadata
In Ecotone any communication happens via Messages, and Messages contains of Payload and Headers (Metadata).
So far we've discussed only the Payload part, for example ProductWasCreated Event Class is actually an Payload.

What we actually store in the Event Stream is Message, so Payload and Metadata.

Ecotone use the Metadata for its own related details, which can be used for identifying messages, correlating, and targeting (which Aggregate it's related too). However we can also use the Metadata for additional information in our Application too.
Metadata Propagation
Ecotone provides Metadata propagation, which take cares of passing Metadata between Command and Events without the need for us to do it manually. This way we can keep our business code clean, yet still be able to access the Metadata later.

Even so, the Metadata is not used in our Ticket Aggregate, when the Event will be stored in the Event Stream, it will be stored along side with our provided Metadata. Therefore we will be able to access it in any Event Handlers:
Manual Propagation
We can also manually add Metadata directly from Command Handler, by packing the our data into Event class.
and then access it from any subflows:
Accessing Metadata in Command Handler
We may access metadata sent from Command Bus in Command Handler when needed:
[Enterprise] Accessing Metadata during Event Application
Pass metadata to #[EventSourcingHandler] methods for context-aware aggregate reconstruction -- without polluting event payloads with infrastructure concerns.
You'll know you need this when:
Your event-sourced aggregates serve multiple tenants and reconstruction logic varies by tenant context
Event streams are merged from multiple source systems and you need to distinguish origin during replay
You need to protect business invariants based on metadata stored alongside events (e.g., executor identity)
This feature is available as part of Ecotone Enterprise.
Last updated
Was this helpful?