mosquitto-rs

Crates.iomosquitto-rs
lib.rsmosquitto-rs
version0.11.2
sourcesrc
created_at2021-01-02 07:44:16.919504
updated_at2024-05-08 14:11:20.716796
descriptionAn async MQTT client based on libmosquitto
homepage
repositoryhttps://github.com/wez/mosquitto-rs
max_upload_size
id330456
size95,267
Wez Furlong (wez)

documentation

https://docs.rs/mosquitto-rs

README

An async MQTT client

build Crates.io

This crate implements an async MQTT client using libmosquitto.

use mosquitto_rs::*;

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

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

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

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

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

        Ok(())
    })
}
Commit count: 47

cargo fmt