pub struct Client { /* private fields */ }
Expand description
A synchronous client, communicates with MQTT EventLoop
.
This is cloneable and can be used to synchronously publish
,
subscribe
through the EventLoop
/Connection
, which is to be polled in parallel
by iterating over the object returned by Connection.iter()
in a separate thread.
NOTE: The EventLoop
/Connection
must be regularly polled(.next()
in case of Connection
) in order
to send, receive and process packets from the broker, i.e. move ahead.
An asynchronous channel handle can also be extracted if necessary.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(options: MqttOptions, cap: usize) -> (Client, Connection)
pub fn new(options: MqttOptions, cap: usize) -> (Client, Connection)
Create a new Client
cap
specifies the capacity of the bounded async channel.
Sourcepub fn from_sender(request_tx: Sender<(NoticeTx, Request)>) -> Client
pub fn from_sender(request_tx: Sender<(NoticeTx, Request)>) -> Client
Create a new Client
from a channel Sender
.
This is mostly useful for creating a test instance where you can listen on the corresponding receiver.
Sourcepub fn publish<S, V>(
&self,
topic: S,
qos: QoS,
retain: bool,
payload: V,
) -> Result<NoticeFuture, ClientError>
pub fn publish<S, V>( &self, topic: S, qos: QoS, retain: bool, payload: V, ) -> Result<NoticeFuture, ClientError>
Sends a MQTT Publish to the EventLoop
pub fn try_publish<S, V>( &self, topic: S, qos: QoS, retain: bool, payload: V, ) -> Result<NoticeFuture, ClientError>
Sourcepub fn ack(&self, publish: &Publish) -> Result<NoticeFuture, ClientError>
pub fn ack(&self, publish: &Publish) -> Result<NoticeFuture, ClientError>
Sends a MQTT PubAck to the EventLoop
. Only needed in if manual_acks
flag is set.
Sourcepub fn try_ack(&self, publish: &Publish) -> Result<(), ClientError>
pub fn try_ack(&self, publish: &Publish) -> Result<(), ClientError>
Sends a MQTT PubAck to the EventLoop
. Only needed in if manual_acks
flag is set.
Sourcepub fn subscribe<S: Into<String>>(
&self,
topic: S,
qos: QoS,
) -> Result<NoticeFuture, ClientError>
pub fn subscribe<S: Into<String>>( &self, topic: S, qos: QoS, ) -> Result<NoticeFuture, ClientError>
Sends a MQTT Subscribe to the EventLoop
Sourcepub fn try_subscribe<S: Into<String>>(
&self,
topic: S,
qos: QoS,
) -> Result<NoticeFuture, ClientError>
pub fn try_subscribe<S: Into<String>>( &self, topic: S, qos: QoS, ) -> Result<NoticeFuture, ClientError>
Sends a MQTT Subscribe to the EventLoop
Sourcepub fn subscribe_many<T>(&self, topics: T) -> Result<NoticeFuture, ClientError>where
T: IntoIterator<Item = SubscribeFilter>,
pub fn subscribe_many<T>(&self, topics: T) -> Result<NoticeFuture, ClientError>where
T: IntoIterator<Item = SubscribeFilter>,
Sends a MQTT Subscribe for multiple topics to the EventLoop
pub fn try_subscribe_many<T>(
&self,
topics: T,
) -> Result<NoticeFuture, ClientError>where
T: IntoIterator<Item = SubscribeFilter>,
Sourcepub fn unsubscribe<S: Into<String>>(
&self,
topic: S,
) -> Result<NoticeFuture, ClientError>
pub fn unsubscribe<S: Into<String>>( &self, topic: S, ) -> Result<NoticeFuture, ClientError>
Sends a MQTT Unsubscribe to the EventLoop
Sourcepub fn try_unsubscribe<S: Into<String>>(
&self,
topic: S,
) -> Result<NoticeFuture, ClientError>
pub fn try_unsubscribe<S: Into<String>>( &self, topic: S, ) -> Result<NoticeFuture, ClientError>
Sends a MQTT Unsubscribe to the EventLoop
Sourcepub fn disconnect(&self) -> Result<NoticeFuture, ClientError>
pub fn disconnect(&self) -> Result<NoticeFuture, ClientError>
Sends a MQTT disconnect to the EventLoop
Sourcepub fn try_disconnect(&self) -> Result<(), ClientError>
pub fn try_disconnect(&self) -> Result<(), ClientError>
Sends a MQTT disconnect to the EventLoop