pub struct Message {
pub payload: Payload,
pub headers: HashMap<String, String>,
}Expand description
A message containing a payload and headers (metadata).
§Automatic Message ID
On construction a UUID v4 is inserted under the message_id header. While you can
override this with set_header, it is discouraged—other infrastructure (logging, tracing)
may rely on uniqueness.
§Correlation ID
Not created automatically to avoid overhead if unused. Call Message::ensure_correlation_id
when a processor needs it. Subsequent calls return the same stable value.
§Header Semantics
All headers are simple UTF-8 strings. Keep values small; store large / complex structures in the payload or properties instead.
Fields§
§payload: PayloadThe message payload.
headers: HashMap<String, String>Arbitrary string headers for metadata.
Implementations§
Source§impl Message
impl Message
Sourcepub fn set_header<K, V>(&mut self, k: K, v: V)
pub fn set_header<K, V>(&mut self, k: K, v: V)
Sets a header key-value pair.
Sourcepub fn ensure_correlation_id(&mut self) -> &str
pub fn ensure_correlation_id(&mut self) -> &str
Ensures a correlation id header exists; returns its value.
If a correlation_id header is present it is returned unchanged; otherwise a new
UUID v4 is generated, inserted, and then returned.
§Use Cases
- Aggregator / Splitter patterns grouping related messages.
- Request/Reply correlation.
- Distributed tracing boundary (can pair with trace/span ids).
Prefer calling once early (or using CorrelationInitializer) rather than sprinkling
calls across processors.