Message Headers
Last updated
Was this helpful?
Last updated
Was this helpful?
Ecotone provides easy way to pass Message Headers (Metadata) with your Message and use it in your Message Handlers or . In case of asynchronous scenarios, Message Headers will be automatically mapped and passed to through your Message Broker.
Pass your metadata (headers), as second parameter.
Then you may access them directly in Message Handlers:
If you have defined for given type, then you may type hint for the object and Ecotone will do the conversion:
And then we can use Classes instead of scalar types for our Headers:
Ecotone by default propagate all Message Headers automatically. This as a result preserve context, which can be used on the later stage. For example we may provide executorId header and skip it in our Command Handler, however use it in resulting Event Handler.
This will execute Command Handler:
and then even so, we don't resend this Header when publishing Event, it will still be available for us:
When publishing Events from Aggregates or Sagas, metadata will be propagated automatically too.
When using Messaging we may want to be able to trace where given Message came from, who was the parent how it was correlated with other Messages. In Ecotone all Messages contains of Message Id, Correlation Id and Parent Id within Metadata. Those are automatically assigned and propagated by the Framework, so from application level code we don’t need to deal manage those Messaging level Concepts.
"parentId" header refers to Message that was direct ancestor of it. In our case that can be correlation of Command and Event. As a result of sending an Command, we publish an Event Message.
Correlation Id is useful for longer flows, which can span over multiple Message Handlers. In those situations we may be interested in how our Message flow have branched:
Ecotone provides a lot of support for Conversion, so we can work with higher level business class not scalars. Find out more in .
Using Message Id, Correlation Id are especially useful find out what have happened during the flow and if any part of the flow has failed. Using already propagated Headers, we may build our own tracing solution on top of what Ecotone provides or use inbuilt support for .
Each Message receives it's own unique Id, which is Uuid generated value. This is used by Ecotone to provide capabilities like , and Message identification for .
Parent id will always refer to the previous Message. What is important however is that, if we have multiple of the Message with same Id.