pub struct MassTransitEnvelope {
pub message_id: Option<String>,
pub correlation_id: Option<String>,
pub source_address: Option<String>,
pub destination_address: Option<String>,
pub sent_time: Option<DateTime<Utc>>,
pub message_type: Option<Vec<String>>,
pub headers: Option<HashMap<String, Value>>,
pub message: Value,
}Expand description
MassTransit message envelope format (C# camelCase JSON)
This structure matches MassTransit’s message envelope format for integration with C# services using MassTransit’s IBus.
MassTransit wraps messages in this format when publishing via IBus.
The actual message payload is in the message field.
According to MassTransit documentation, messageType should be an array of URNs in the format: “urn:message:Namespace:TypeName”
Fields§
§message_id: Option<String>Auto-generated message ID (Guid in C#)
correlation_id: Option<String>Correlation ID for tracking operations (Guid? in C#)
source_address: Option<String>Source address (Uri in C#)
destination_address: Option<String>Destination address (Uri in C#)
sent_time: Option<DateTime<Utc>>Sent time (DateTime? in C#)
message_type: Option<Vec<String>>Message type array - array of URNs in format “urn:message:Namespace:TypeName” This is required for MassTransit to properly route messages
headers: Option<HashMap<String, Value>>Headers (Dictionary<string, object> in C#)
message: ValueThe actual message payload (this is what we care about) MassTransit wraps the actual message in this field
Implementations§
Source§impl MassTransitEnvelope
impl MassTransitEnvelope
Sourcepub fn new<T>(message: &T) -> Result<Self, Error>where
T: Serialize,
pub fn new<T>(message: &T) -> Result<Self, Error>where
T: Serialize,
Create a new MassTransit envelope with a message payload This automatically generates a message ID (Guid format) and sets sent_time
Sourcepub fn with_message_type<T>(
message: &T,
message_type: &str,
) -> Result<Self, Error>where
T: Serialize,
pub fn with_message_type<T>(
message: &T,
message_type: &str,
) -> Result<Self, Error>where
T: Serialize,
Create a MassTransit envelope with message type for proper routing MassTransit uses message type names for routing (e.g., “YourNamespace:YourMessageType”) The message type will be added as an array in the envelope body AND in headers for full compatibility
Message type can be in format:
- “Namespace:TypeName” (will be converted to “urn:message:Namespace:TypeName”)
- “urn:message:Namespace:TypeName” (used as-is)
Sourcepub fn with_correlation_id(self, correlation_id: impl Into<String>) -> Self
pub fn with_correlation_id(self, correlation_id: impl Into<String>) -> Self
Set correlation ID for tracking operations
Sourcepub fn with_source_address(self, source_address: impl Into<String>) -> Self
pub fn with_source_address(self, source_address: impl Into<String>) -> Self
Set source address (typically “rabbitmq://host/exchange”)
Sourcepub fn with_destination_address(
self,
destination_address: impl Into<String>,
) -> Self
pub fn with_destination_address( self, destination_address: impl Into<String>, ) -> Self
Set destination address (typically “rabbitmq://host/queue”)
Sourcepub fn with_header(self, key: impl Into<String>, value: Value) -> Self
pub fn with_header(self, key: impl Into<String>, value: Value) -> Self
Add custom header
Sourcepub fn with_message_type_header(self, message_type: &str) -> Self
pub fn with_message_type_header(self, message_type: &str) -> Self
Set message type in envelope body and headers (required for MassTransit routing) MassTransit expects message types as an array in both envelope body and MT-Host-MessageType header Message type can be in format “Namespace:TypeName” or “urn:message:Namespace:TypeName”
Sourcepub fn extract_message<T>(&self) -> Result<T, Error>where
T: for<'de> Deserialize<'de>,
pub fn extract_message<T>(&self) -> Result<T, Error>where
T: for<'de> Deserialize<'de>,
Extract the actual message payload as the specified type
Sourcepub fn correlation_id(&self) -> Option<&str>
pub fn correlation_id(&self) -> Option<&str>
Get correlation ID if present
Sourcepub fn message_id(&self) -> Option<&str>
pub fn message_id(&self) -> Option<&str>
Get message ID if present
Sourcepub fn from_slice(bytes: &[u8]) -> Result<Self, Error>
pub fn from_slice(bytes: &[u8]) -> Result<Self, Error>
Try to deserialize a MassTransit envelope from JSON bytes
Trait Implementations§
Source§impl Clone for MassTransitEnvelope
impl Clone for MassTransitEnvelope
Source§fn clone(&self) -> MassTransitEnvelope
fn clone(&self) -> MassTransitEnvelope
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more