Crates.io | rumqttc-dev-patched |
lib.rs | rumqttc-dev-patched |
version | 0.24.0-devpatch+9109f87 |
source | src |
created_at | 2024-09-24 14:43:53.538744 |
updated_at | 2024-09-24 14:45:42.238954 |
description | An efficient and robust mqtt client for your connected devices |
homepage | |
repository | https://github.com/bytebeamio/rumqtt |
max_upload_size | |
id | 1385299 |
size | 579,563 |
A pure rust MQTT client which strives to be robust, efficient and easy to use. This library is backed by an async(using tokio) eventloop which enables users to send and receive MQTT messages in correspondence with a broker.
use rumqttc::{MqttOptions, Client, QoS};
use std::time::Duration;
use std::thread;
let mut mqttoptions = MqttOptions::new("rumqtt-sync", "test.mosquitto.org", 1883);
mqttoptions.set_keep_alive(Duration::from_secs(5));
let (mut client, mut connection) = Client::new(mqttoptions, 10);
client.subscribe("hello/rumqtt", QoS::AtMostOnce).unwrap();
thread::spawn(move || for i in 0..10 {
client.publish("hello/rumqtt", QoS::AtLeastOnce, false, vec![i; i as usize]).unwrap();
thread::sleep(Duration::from_millis(100));
});
// Iterate to poll the eventloop for connection progress
for (i, notification) in connection.iter().enumerate() {
println!("Notification = {:?}", notification);
}
use rumqttc::{MqttOptions, AsyncClient, QoS};
use tokio::{task, time};
use std::time::Duration;
use std::error::Error;
let mut mqttoptions = MqttOptions::new("rumqtt-async", "test.mosquitto.org", 1883);
mqttoptions.set_keep_alive(Duration::from_secs(5));
let (mut client, mut eventloop) = AsyncClient::new(mqttoptions, 10);
client.subscribe("hello/rumqtt", QoS::AtMostOnce).await.unwrap();
task::spawn(async move {
for i in 0..10 {
client.publish("hello/rumqtt", QoS::AtLeastOnce, false, vec![i; i as usize]).await.unwrap();
time::sleep(Duration::from_millis(100)).await;
}
});
while let Ok(notification) = eventloop.poll().await {
println!("Received = {:?}", notification);
}
Quick overview of features
eventloop.poll()/connection.iter()
loopIn short, everything necessary to maintain a robust connection
Since the eventloop is externally polled (with iter()/poll()
in a loop)
out side the library and Eventloop
is accessible, users can
Looping on connection.iter()
/eventloop.poll()
is necessary to run the
event loop and make progress. It yields incoming and outgoing activity
notifications which allows customization as you see fit.
Blocking inside the connection.iter()
/eventloop.poll()
loop will block
connection progress.