pub struct SyncTopic<'a> { /* private fields */ }
Expand description
A topic destination for messages.
This keeps message parameters for repeatedly publishing to the same topic on a server.
Implementations§
source§impl<'a> SyncTopic<'a>
impl<'a> SyncTopic<'a>
sourcepub fn new<T>(cli: &'a Client, topic: T, qos: i32) -> Self
pub fn new<T>(cli: &'a Client, topic: T, qos: i32) -> Self
Creates a new topic object for publishing messages.
§Arguments
cli
The client used to publish the messages.
topic
The topic on which to publish the messages
qos
The quality of service for messages
sourcepub fn new_retained<T>(cli: &'a Client, topic: T, qos: i32) -> Self
pub fn new_retained<T>(cli: &'a Client, topic: T, qos: i32) -> Self
Creates a new topic object for publishing messages.
§Arguments
cli
The client used to publish the messages.
topic
The topic on which to publish the messages
qos
The quality of service for messages
sourcepub fn create_message<V>(&self, payload: V) -> Message
pub fn create_message<V>(&self, payload: V) -> Message
Create a message for the topic using the supplied payload
sourcepub fn subscribe(&self) -> Result<ServerResponse>
pub fn subscribe(&self) -> Result<ServerResponse>
Subscribe to the topic.
sourcepub fn subscribe_with_options<T, P>(
&self,
opts: T,
props: P
) -> Result<ServerResponse>
pub fn subscribe_with_options<T, P>( &self, opts: T, props: P ) -> Result<ServerResponse>
Subscribe to the topic with subscription options.
sourcepub fn publish<V>(&self, payload: V) -> Result<()>
pub fn publish<V>(&self, payload: V) -> Result<()>
Publish a message on the topic.
If a topic alias was previously sent, this will use the integer alias property instead of sending the topic string. Topic aliases are only applicable for MQTT v5 connections.
§Arguments
payload
The payload of the message
sourcepub fn publish_with_alias<V>(&mut self, alias: u16, payload: V) -> Result<()>
pub fn publish_with_alias<V>(&mut self, alias: u16, payload: V) -> Result<()>
Publish a message with a topic alias.
This publishes the message with a topic alias property to set the alias at the broker. After calling this, the object keeps the alias and uses it for subsequent publishes instead of sending the full topic string.
Note that using an alias is only valid with an MQTT v5 connection, and the value must be in the range of 1 - TopicAliasMaximum as the broker reported in the CONNACK packet. The alias is only valid for a single connection. It should be reset on a reconnect.
This can be called a second time to change the alias setting. Using an alias of zero on a subsequent call instructs this object to stop using the alias and publish with the topic name.
§Arguments
alias
The integer alias to use for subsequent message publishing.
This must be in the range 1 - TopicAliasMaximum
as reported by
the server in the CONNACK package. Using a value of zero
instructs this object to stop using the alias and go back to
publishing with the string topic name.
payload
The payload of the message
sourcepub fn remove_alias(&mut self)
pub fn remove_alias(&mut self)
Removes the alias, if any, from the topic.
After removing the alias, publshed messages contain the full string topic. The alias mapping remains on the server though. The alias number cann be reused by assigning to a different topic, but the only way to remove it is to disconnect the client.