Struct paho_mqtt::async_client::AsyncClient
[−]
[src]
pub struct AsyncClient { /* fields omitted */ }
An asynchronous MQTT connection client.
Methods
impl AsyncClient
[src]
fn new<T>(opts: T) -> MqttResult<AsyncClient> where
T: Into<CreateOptions>,
T: Into<CreateOptions>,
Creates a new MQTT client which can connect to an MQTT broker.
Arguments
server_uri
The address of the MQTT broker.client_id
The unique name of the client. if this is empty, the the broker will assign a unique name.
fn connect<T>(&self, opt_opts: T) -> Arc<Token> where
T: Into<Option<ConnectOptions>>,
T: Into<Option<ConnectOptions>>,
fn connect_with_callbacks<FS, FF>(
&self,
opts: ConnectOptions,
success_cb: FS,
failure_cb: FF
) -> Arc<Token> where
FS: FnMut(&AsyncClient, u16) + 'static,
FF: FnMut(&AsyncClient, u16, i32) + 'static,
&self,
opts: ConnectOptions,
success_cb: FS,
failure_cb: FF
) -> Arc<Token> where
FS: FnMut(&AsyncClient, u16) + 'static,
FF: FnMut(&AsyncClient, u16, i32) + 'static,
fn reconnect(&self) -> Arc<Token>
Attempts to reconnect to the broker. This can only be called after a connection was initially made or attempted. It will retry with the same connect options.
fn reconnect_with_callbacks<FS, FF>(
&self,
success_cb: FS,
failure_cb: FF
) -> Arc<Token> where
FS: FnMut(&AsyncClient, u16) + 'static,
FF: FnMut(&AsyncClient, u16, i32) + 'static,
&self,
success_cb: FS,
failure_cb: FF
) -> Arc<Token> where
FS: FnMut(&AsyncClient, u16) + 'static,
FF: FnMut(&AsyncClient, u16, i32) + 'static,
Attempts to reconnect to the broker, using callbacks to signal completion. This can only be called after a connection was initially made or attempted. It will retry with the same connect options.
Arguments
success_cb
The callback for a successful connection.failure_cb
The callback for a failed connection attempt.
fn disconnect<T>(&self, opt_opts: T) -> Arc<Token> where
T: Into<Option<DisconnectOptions>>,
T: Into<Option<DisconnectOptions>>,
Disconnects from the MQTT broker.
Arguments
opt_opts
Optional disconnect options. Specifying None
will use
default of immediate (zero timeout) disconnect.
fn disconnect_after(&self, timeout: Duration) -> Arc<Token>
Disconnect from the MQTT broker with a timeout. This will delay the disconnect for up to the specified timeout to allow in-flight messages to complete. This is the same as calling disconnect with options specifying a timeout.
Arguments
timeout
The amount of time to wait for the disconnect. This has
a resolution in milliseconds.
fn is_connected(&self) -> bool
Determines if this client is currently connected to an MQTT broker.
fn set_connection_lost_callback<F>(&mut self, cb: F) where
F: FnMut(&mut AsyncClient) + 'static,
F: FnMut(&mut AsyncClient) + 'static,
Sets the callback for when the connection is lost with the broker.
Arguments
cb
The callback to register with the library. This can be a function or a closure.
fn set_message_callback<F>(&mut self, cb: F) where
F: FnMut(&AsyncClient, Message) + 'static,
F: FnMut(&AsyncClient, Message) + 'static,
Sets the callback for when a message arrives from the broker.
Arguments
cb
The callback to register with the library. This can be a function or a closure.
fn publish(&self, msg: Message) -> Arc<DeliveryToken>
fn subscribe(&self, topic: &str, qos: i32) -> Arc<Token>
Subscribes to a single topic.
Arguments
topic
The topic name
qos
The quality of service requested for messages
fn subscribe_many(&self, topic: Vec<String>, qos: Vec<i32>) -> Arc<Token>
Subscribes to multiple topics simultaneously.
Arguments
topic
The topic name
qos
The quality of service requested for messages
fn unsubscribe(&self, topic: &str) -> Arc<Token>
Unsubscribes from a single topic.
Arguments
topic
The topic to unsubscribe. It must match a topic from a
previous subscribe.
fn unsubscribe_many(&self, topic: Vec<String>) -> Arc<Token>
Unsubscribes from multiple topics simultaneously.
Arguments
topic
The topics to unsubscribe. Each must match a topic from a
previous subscribe.
fn start_consuming(&mut self) -> Receiver<Message>
Start consuming incoming messages. This initializes the client to receive messages into an internal queue which can be read synchronously.