pub struct Message {
pub topic: String,
pub payload: Vec<u8>,
pub key: Option<String>,
pub timestamp: i64,
pub headers: HashMap<String, String>,
pub id: String,
pub retry_count: u32,
}Expand description
消息体
包含 topic、payload、key、timestamp、headers、id 以及重试次数 retry_count。
Fields§
§topic: String§payload: Vec<u8>§key: Option<String>§timestamp: i64§headers: HashMap<String, String>§id: String§retry_count: u32重试次数(nack 时递增,达到 max_retries 后转入死信队列)
Implementations§
Source§impl Message
impl Message
pub fn new(topic: impl Into<String>, payload: Vec<u8>) -> Self
pub fn with_key(self, key: impl Into<String>) -> Self
pub fn text(&self) -> Option<&str>
pub fn json<T: DeserializeOwned>(&self) -> Option<T>
pub fn text_message(topic: impl Into<String>, text: impl Into<String>) -> Self
pub fn json_message<T: Serialize>( topic: impl Into<String>, data: &T, ) -> Result<Self, MqError>
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 UnsafeUnpin for Message
impl UnwindSafe for Message
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