Crate mosquitto_rs

source ·
Expand description

This crate implements an async MQTT client using libmosquitto.

use mosquitto_rs::*;

fn main() -> Result<(), Error> {
    smol::block_on(async {
        let mut client = Client::with_auto_id()?;
        let rc = client.connect(
                       "localhost", 1883,
                       std::time::Duration::from_secs(5), None).await?;
        println!("connect: {}", rc);

        let subscriptions = client.subscriber().unwrap();

        client.subscribe("test", QoS::AtMostOnce).await?;
        println!("subscribed");

        client.publish("test", b"woot", QoS::AtMostOnce, false)
            .await?;
        println!("published");

        if let Ok(msg) = subscriptions.recv().await {
            println!("msg: {:?}", msg);
        }

        Ok(())
    })
}

Features

The following feature flags are available:

  • router - include the router module and MqttRouter type. This is on by default.
  • vendored-mosquitto - use bundled libmosquitto 2.4 library. This is on by default.
  • vendored-mosquitto-tls - enable tls support in the bundled libmosquitto. This is on by default.
  • vendored-openssl - build openssl from source, rather than using the system library. Recommended for macOS and Windows users to enable this.

Modules

Structs

Enums

Traits

  • Defines handlers that can be used to determine when various functions have completed. Take care: the underlying mosquitto library can make nested/reentrant calls through your Callbacks implementation. If you use interior mutability, be sure to limit the scope/duration of any locks such that they do no encompass any other calls (such as attempts to publish or subscribe) into mosquitto.

Functions

  • Returns the version information for the linked mosquitto library

Type Aliases

  • Represents an individual message identifier. This is used in this client to determine when a message has been sent.
  • An OpenSSL password callback (see man SSL_CTX_set_default_passwd_cb_userdata).