pub struct AsyncClient { /* private fields */ }
Expand description

An asynchronous MQTT connection client.

Implementations

Creates a new MQTT client which can connect to an MQTT broker.

Arguments

opts The create options for the client.

Gets the MQTT version for which the client was created.

This is the default version used when connecting, unless a specific value is set in the connect options. It is typically the highest version that can be used by the client. Specifically, if the client is created for v3, then it can not be used to connect with the v5 protocol.

The current version of the protol being used, if the client is connected.

Get access to the user-defined data in the client.

This returns a reference to a read/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.

Connects to an MQTT broker using the specified connect options.

Arguments
  • opts The connect options. This can be None, in which case the default options are used.

Connects to an MQTT broker using the specified connect options.

Arguments
  • opts The connect options
  • success_cb The callback for a successful connection.
  • failure_cb The callback for a failed connection attempt.

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.

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.

Disconnects from the MQTT broker.

Arguments

opt_opts Optional disconnect options. Specifying None will use default of immediate (zero timeout) disconnect.

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.

Determines if this client is currently connected to an MQTT broker.

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.

Removes the callback for when the conection is established

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.

Removes the callback for when the connection is lost

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.

Removes the callback for when a disconnect message is received from the broker.

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.

Removes the callback for when a message arrives from the broker.

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.

Publishes a message to the MQTT broker.

Returns a Delivery Token to track the progress of the operation.

Subscribes to a single topic.

Arguments

topic The topic name qos The quality of service requested for messages

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

Subscribes to multiple topics simultaneously.

Arguments

topics The collection of topic names qos The quality of service requested for messages

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

Unsubscribes from a single topic.

Arguments

topic The topic to unsubscribe. It must match a topic from a previous subscribe.

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.

Unsubscribes from multiple topics simultaneously.

Arguments

topic The topics to unsubscribe. Each must match a topic from a previous subscribe.

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.

Starts the client consuming messages for a blocking (non-async) app.

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.

Stops the client from consuming messages.

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.

Stops the client from streaming messages in.

Returns client ID used for client instance

Client ID is returned as a rust String as set in a CreateOptionsBuilder for symmetry

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.