pub struct Envelope {
pub id: MessageId,
pub route: RouteKey,
pub headers: BTreeMap<String, String>,
pub content_type: ContentType,
pub payload: Bytes,
}Expand description
Protocol-agnostic unit of data that crosses the engine.
The engine reads only Self::route. Headers, content type, and
payload are opaque and are cloned to every matching subscriber.
Header names are namespaced by owner (oag., stomp., agra.);
that convention is not enforced here.
Fields§
§id: MessageIdGateway-assigned id, not a protocol message id.
route: RouteKeyThe only field crate::Engine::publish matches on.
headers: BTreeMap<String, String>String pairs adapters stamp and read. The engine never looks here.
content_type: ContentTypeHow the payload is labelled, not how the engine parses it.
payload: BytesUninterpreted bytes. JSON, XML, or anything else.
Implementations§
Source§impl Envelope
impl Envelope
Sourcepub fn new(route: RouteKey, payload: impl Into<Bytes>) -> Self
pub fn new(route: RouteKey, payload: impl Into<Bytes>) -> Self
Builds an envelope with a fresh MessageId, no headers, and
ContentType::octet_stream.
Call Self::with_content_type when the bytes are known to be
JSON or XML. The default is octet-stream because this constructor
does not inspect payload.
Sourcepub fn with_content_type(self, content_type: ContentType) -> Self
pub fn with_content_type(self, content_type: ContentType) -> Self
Sets the content-type label. Does not parse or convert payload.
Sourcepub fn with_header(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Inserts or replaces one header. Last write for a key wins.
Sourcepub fn with_origin(self, id: &AdapterId) -> Self
pub fn with_origin(self, id: &AdapterId) -> Self
Stamps HDR_ORIGIN so a bridging adapter can refuse its own
echo. Last write wins.
Sourcepub fn origin(&self) -> Option<&str>
pub fn origin(&self) -> Option<&str>
Value of HDR_ORIGIN, if stamped.
Sourcepub fn is_echo_of(&self, id: &AdapterId) -> bool
pub fn is_echo_of(&self, id: &AdapterId) -> bool
Whether this envelope was published by id’s inbound path.
Bridging adapters skip outbound-to-the-same-bus when this is true. The engine does not skip: one adapter id may cover many connections (OWP).