Struct PublishBuilder
pub struct PublishBuilder<'a> {
cmd_tx: &'a Sender<Command>,
topic: TopicBuf,
payload: Vec<u8>,
qos: QoS,
retain: bool,
properties: PublishProperties,
}Expand description
Builder for publishing a message with optional MQTT v5 properties.
Obtained via MqttClient::publish.
Call send to enqueue the message (non-async, returns
immediately) or send_async to wait for command
queue space.
Fields§
§cmd_tx: &'a Sender<Command>§topic: TopicBuf§payload: Vec<u8>§qos: QoS§retain: bool§properties: PublishPropertiesImplementations§
§impl<'a> PublishBuilder<'a>
impl<'a> PublishBuilder<'a>
pub(crate) fn new( cmd_tx: &'a Sender<Command>, topic: TopicBuf, payload: Vec<u8>, ) -> Self
pub fn content_type(self, ct: MqttString) -> Self
pub fn content_type(self, ct: MqttString) -> Self
Set the MIME content type (property 0x03).
pub fn response_topic(self, topic: TopicBuf) -> Self
pub fn response_topic(self, topic: TopicBuf) -> Self
Set the response topic for request/response flows (property 0x08).
pub fn correlation_data(self, data: MqttBytesBuf) -> Self
pub fn correlation_data(self, data: MqttBytesBuf) -> Self
Set correlation data for request/response flows (property 0x09).
pub const fn message_expiry(self, seconds: u32) -> Self
pub const fn message_expiry(self, seconds: u32) -> Self
Set the message expiry interval in seconds (property 0x02).
pub const fn payload_format(self, format: PayloadFormat) -> Self
pub const fn payload_format(self, format: PayloadFormat) -> Self
Indicate whether the payload is UTF-8 encoded (property 0x01).
pub fn user_property(self, key: MqttString, value: MqttString) -> Self
pub fn user_property(self, key: MqttString, value: MqttString) -> Self
Add a user property key-value pair (property 0x26).
May be called multiple times.
pub fn send(self) -> Result<PublishToken, Error>
pub fn send(self) -> Result<PublishToken, Error>
Enqueue the publish (non-blocking).
Returns a PublishToken that can be used to track progress
and await the broker acknowledgement.
§Errors
Returns Error::ConnectionClosed if the internal command queue
is full or the connection has been shut down.
pub async fn send_async(self) -> Result<PublishToken, Error>
pub async fn send_async(self) -> Result<PublishToken, Error>
Enqueue the publish, waiting for queue space if necessary.
Like send but applies back-pressure instead of
failing when the queue is full.
§Errors
Returns Error::ConnectionClosed if the connection has been shut
down.