pub struct Message {
pub id: String,
pub payload: Vec<u8>,
pub headers: HashMap<String, String>,
pub topic: String,
pub timestamp: DateTime<Utc>,
pub correlation_id: Option<String>,
pub reply_to: Option<String>,
pub content_type: Option<String>,
pub priority: Option<u8>,
pub ttl: Option<u64>,
}Expand description
A message to be sent or received from a message broker
Fields§
§id: StringUnique message identifier
payload: Vec<u8>Message payload as bytes
headers: HashMap<String, String>Message headers/properties
topic: StringTopic/queue/subject the message belongs to
timestamp: DateTime<Utc>Timestamp when the message was created
correlation_id: Option<String>Optional correlation ID for request-response patterns
reply_to: Option<String>Optional reply-to address
content_type: Option<String>Message content type (e.g., “application/json”)
priority: Option<u8>Message priority (0-9, where 9 is highest)
ttl: Option<u64>Time-to-live in milliseconds
Implementations§
Source§impl Message
impl Message
Sourcepub fn new<T: Into<Vec<u8>>>(topic: impl Into<String>, payload: T) -> Self
pub fn new<T: Into<Vec<u8>>>(topic: impl Into<String>, payload: T) -> Self
Create a new message with the given payload
Sourcepub fn json<T: Serialize>(
topic: impl Into<String>,
value: &T,
) -> Result<Self, MessagingError>
pub fn json<T: Serialize>( topic: impl Into<String>, value: &T, ) -> Result<Self, MessagingError>
Create a message from a JSON-serializable value
Sourcepub fn parse_json<T: for<'de> Deserialize<'de>>(
&self,
) -> Result<T, MessagingError>
pub fn parse_json<T: for<'de> Deserialize<'de>>( &self, ) -> Result<T, MessagingError>
Parse the payload as JSON
Sourcepub fn payload_str(&self) -> Result<&str, MessagingError>
pub fn payload_str(&self) -> Result<&str, MessagingError>
Get the payload as a UTF-8 string
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
Add a header to the message
Sourcepub fn with_correlation_id(self, id: impl Into<String>) -> Self
pub fn with_correlation_id(self, id: impl Into<String>) -> Self
Set the correlation ID
Sourcepub fn with_reply_to(self, reply_to: impl Into<String>) -> Self
pub fn with_reply_to(self, reply_to: impl Into<String>) -> Self
Set the reply-to address
Sourcepub fn with_content_type(self, content_type: impl Into<String>) -> Self
pub fn with_content_type(self, content_type: impl Into<String>) -> Self
Set the content type
Sourcepub fn with_priority(self, priority: u8) -> Self
pub fn with_priority(self, priority: u8) -> Self
Set the priority (0-9)
Sourcepub fn with_ttl_duration(self, ttl: Duration) -> Self
pub fn with_ttl_duration(self, ttl: Duration) -> Self
Set the time-to-live from a Duration
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.