Crates.io | mosquitto-rs |
lib.rs | mosquitto-rs |
version | 0.11.2 |
source | src |
created_at | 2021-01-02 07:44:16.919504 |
updated_at | 2024-05-08 14:11:20.716796 |
description | An async MQTT client based on libmosquitto |
homepage | |
repository | https://github.com/wez/mosquitto-rs |
max_upload_size | |
id | 330456 |
size | 95,267 |
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(())
})
}