pub struct Message<T> {
pub topic: String,
pub key: Option<String>,
pub payload: T,
pub headers: HashMap<String, String>,
pub timestamp: DateTime<Utc>,
pub partition: Option<i32>,
pub offset: Option<i64>,
}Expand description
A generic message that can be sent to or received from a message broker.
Fields§
§topic: StringThe topic or channel the message belongs to.
key: Option<String>Optional partitioning key.
payload: TThe message payload.
headers: HashMap<String, String>Arbitrary key-value headers attached to the message.
timestamp: DateTime<Utc>Timestamp when the message was created.
partition: Option<i32>The partition the message was sent to or read from.
offset: Option<i64>The offset within the partition.
Implementations§
Source§impl<T> Message<T>
impl<T> Message<T>
Sourcepub fn new(topic: impl Into<String>, payload: T) -> Self
pub fn new(topic: impl Into<String>, payload: T) -> Self
Create a new message for the given topic with the provided 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
Attach a single header.
Sourcepub fn with_message_id(self) -> Self
pub fn with_message_id(self) -> Self
Attach a unique message-id header.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Message<T>where
T: Freeze,
impl<T> RefUnwindSafe for Message<T>where
T: RefUnwindSafe,
impl<T> Send for Message<T>where
T: Send,
impl<T> Sync for Message<T>where
T: Sync,
impl<T> Unpin for Message<T>where
T: Unpin,
impl<T> UnsafeUnpin for Message<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Message<T>where
T: UnwindSafe,
Blanket Implementations§
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