[−][src]Struct paho_mqtt::async_client::AsyncClient
An asynchronous MQTT connection client.
Implementations
impl AsyncClient
[src]
pub fn new<T>(opts: T) -> Result<AsyncClient> where
T: Into<CreateOptions>,
[src]
T: Into<CreateOptions>,
Creates a new MQTT client which can connect to an MQTT broker.
Arguments
opts
The create options for the client.
pub fn mqtt_version(&self) -> u32
[src]
Gets the MQTT version for vhich the client was created.
pub fn user_data(&self) -> Option<&UserData>
[src]
Get access to the user-defined data in the client.
This returns a reference to aread/write lock around the user data so that the application can access the data, as needed from any outside thread or a callback.
Note that it's up to the application to ensure that it doesn't deadlock the callback thread when accessing the user data.
pub fn connect<T>(&self, opt_opts: T) -> ConnectToken where
T: Into<Option<ConnectOptions>>,
[src]
T: Into<Option<ConnectOptions>>,
pub fn connect_with_callbacks<FS, FF>(
&self,
opts: ConnectOptions,
success_cb: FS,
failure_cb: FF
) -> ConnectToken where
FS: Fn(&AsyncClient, u16) + 'static,
FF: Fn(&AsyncClient, u16, i32) + 'static,
[src]
&self,
opts: ConnectOptions,
success_cb: FS,
failure_cb: FF
) -> ConnectToken where
FS: Fn(&AsyncClient, u16) + 'static,
FF: Fn(&AsyncClient, u16, i32) + 'static,
pub fn reconnect(&self) -> ConnectToken
[src]
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.
pub fn reconnect_with_callbacks<FS, FF>(
&self,
success_cb: FS,
failure_cb: FF
) -> ConnectToken where
FS: Fn(&AsyncClient, u16) + 'static,
FF: Fn(&AsyncClient, u16, i32) + 'static,
[src]
&self,
success_cb: FS,
failure_cb: FF
) -> ConnectToken where
FS: Fn(&AsyncClient, u16) + 'static,
FF: Fn(&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.
pub fn disconnect<T>(&self, opt_opts: T) -> Tokenⓘ where
T: Into<Option<DisconnectOptions>>,
[src]
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.
pub fn disconnect_after(&self, timeout: Duration) -> Tokenⓘ
[src]
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.
pub fn is_connected(&self) -> bool
[src]
Determines if this client is currently connected to an MQTT broker.
pub fn set_connected_callback<F>(&mut self, cb: F) where
F: FnMut(&AsyncClient) + 'static,
[src]
F: FnMut(&AsyncClient) + 'static,
Sets the callback for when the connection is established with the broker.
Arguments
cb
The callback to register with the library. This can be a function or a closure.
pub fn set_connection_lost_callback<F>(&mut self, cb: F) where
F: FnMut(&AsyncClient) + 'static,
[src]
F: FnMut(&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.
pub fn set_disconnected_callback<F>(&mut self, cb: F) where
F: FnMut(&AsyncClient, Properties, ReasonCode) + 'static,
[src]
F: FnMut(&AsyncClient, Properties, ReasonCode) + 'static,
Sets the callback for when a disconnect message arrives from the broker.
Arguments
cb
The callback to register with the library. This can be a function or a closure.
pub fn set_message_callback<F>(&mut self, cb: F) where
F: FnMut(&AsyncClient, Option<Message>) + 'static,
[src]
F: FnMut(&AsyncClient, Option<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.
pub fn try_publish(&self, msg: Message) -> Result<DeliveryToken>
[src]
Attempts to publish a message to the MQTT broker, but returns an error immediately if there's a problem creating or queuing the message.
Returns a Publish Error on failure so that the original message can be recovered and sent again.
pub fn publish(&self, msg: Message) -> DeliveryTokenⓘNotable traits for DeliveryToken
impl Future for DeliveryToken type Output = Result<()>;
[src]
Notable traits for DeliveryToken
impl Future for DeliveryToken type Output = Result<()>;
Publishes a message to the MQTT broker.
Returns a Delivery Token to track the progress of the operation.
pub fn subscribe<S>(&self, topic: S, qos: i32) -> SubscribeToken where
S: Into<String>,
[src]
S: Into<String>,
Subscribes to a single topic.
Arguments
topic
The topic name
qos
The quality of service requested for messages
pub fn subscribe_with_options<S, T, P>(
&self,
topic: S,
qos: i32,
opts: T,
props: P
) -> SubscribeToken where
S: Into<String>,
T: Into<SubscribeOptions>,
P: Into<Option<Properties>>,
[src]
&self,
topic: S,
qos: i32,
opts: T,
props: P
) -> SubscribeToken where
S: Into<String>,
T: Into<SubscribeOptions>,
P: Into<Option<Properties>>,
Subscribes to a single topic with v5 options
Arguments
topic
The topic name
qos
The quality of service requested for messages
opts
Options for the subscription
props
MQTT v5 properties
pub fn subscribe_many<T>(&self, topics: &[T], qos: &[i32]) -> SubscribeManyToken where
T: AsRef<str>,
[src]
T: AsRef<str>,
Subscribes to multiple topics simultaneously.
Arguments
topics
The collection of topic names
qos
The quality of service requested for messages
pub fn subscribe_many_with_options<T, P>(
&self,
topics: &[T],
qos: &[i32],
opts: &[SubscribeOptions],
props: P
) -> SubscribeManyToken where
T: AsRef<str>,
P: Into<Option<Properties>>,
[src]
&self,
topics: &[T],
qos: &[i32],
opts: &[SubscribeOptions],
props: P
) -> SubscribeManyToken where
T: AsRef<str>,
P: Into<Option<Properties>>,
Subscribes to multiple topics simultaneously with options.
Arguments
topics
The collection of topic names
qos
The quality of service requested for messages
opts
Subscribe options (one per topic)
props
MQTT v5 properties
pub fn unsubscribe<S>(&self, topic: S) -> Tokenⓘ where
S: Into<String>,
[src]
S: Into<String>,
Unsubscribes from a single topic.
Arguments
topic
The topic to unsubscribe. It must match a topic from a
previous subscribe.
pub fn unsubscribe_with_options<S>(&self, topic: S, props: Properties) -> Tokenⓘ where
S: Into<String>,
[src]
S: Into<String>,
Unsubscribes from a single topic.
Arguments
topic
The topic to unsubscribe. It must match a topic from a
previous subscribe.
props
MQTT v5 properties for the unsubscribe.
pub fn unsubscribe_many<T>(&self, topics: &[T]) -> Tokenⓘ where
T: AsRef<str>,
[src]
T: AsRef<str>,
Unsubscribes from multiple topics simultaneously.
Arguments
topic
The topics to unsubscribe. Each must match a topic from a
previous subscribe.
pub fn unsubscribe_many_with_options<T>(
&self,
topics: &[T],
props: Properties
) -> Tokenⓘ where
T: AsRef<str>,
[src]
&self,
topics: &[T],
props: Properties
) -> Tokenⓘ where
T: AsRef<str>,
Unsubscribes from multiple topics simultaneously.
Arguments
topic
The topics to unsubscribe. Each must match a topic from a
previous subscribe.
props
MQTT v5 properties for the unsubscribe.
pub fn start_consuming(&mut self) -> Receiver<Option<Message>>
[src]
Starts the client consuming messages. This starts the client receiving messages and placing them into an mpsc queue. It returns the receiving-end of the queue for the application to get the messages. This can be called at any time after the client is created, but it should be called before subscribing to any topics, otherwise messages can be lost.
pub fn stop_consuming(&self)
[src]
Stops the client from consuming messages.
pub fn get_stream(&mut self, buffer_sz: usize) -> Receiver<Option<Message>>
[src]
Creates a futures stream for consuming messages.
This will install an internal callback to receive the incoming
messages from the client, and return the receive side of the channel.
The stream will stay open for the life of the client. If the client
gets disconnected, it will insert None
into the channel to signal
the app about the disconnect.
It's a best practice to open the stream before connecting to the server. When using persistent (non-clean) sessions, messages could arriving as soon as the connection is made - even before the connect() call returns.
Trait Implementations
impl Clone for AsyncClient
[src]
pub fn clone(&self) -> AsyncClient
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Send for AsyncClient
[src]
impl Sync for AsyncClient
[src]
Auto Trait Implementations
impl !RefUnwindSafe for AsyncClient
[src]
impl Unpin for AsyncClient
[src]
impl !UnwindSafe for AsyncClient
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,