Crate finmqtt_tokio
Expand description
Session-oriented MQTT v5 client built on [tokio] and
finmqtt-core.
ยงQuick start
use finmqtt_core::wire::QoS;
use finmqtt_tokio::transport::TcpTransport;
use finmqtt_tokio::{ClientOptions, MqttClient, MqttString, TopicBuf, TopicFilterBuf};
use futures::StreamExt;
let transport = TcpTransport::new("broker.example.com", 1883);
let options = ClientOptions::new("my-client".parse()?).reconnect();
let (client, mut messages) = MqttClient::new(transport, options).await?;
// Subscribe โ pure protocol operation, returns SUBACK reason codes.
let reason_codes = client
.subscribe("sensors/#".parse()?)
.qos(QoS::AtLeastOnce)
.send()
.await?;
// Publish with v5 properties:
client
.publish("sensors/temp".parse()?, b"22.5".as_slice())
.qos(QoS::AtLeastOnce)
.send()?;
// All messages arrive on the single message stream:
while let Some(msg) = messages.next().await {
println!("{}: {:?}", msg.topic, msg.payload);
}Re-exportsยง
pub use self::message::Message;pub use self::message::MessageStream;pub use self::options::ClientOptions;pub use self::token::PublishToken;
Modulesยง
- client ๐
- Session-oriented MQTT v5 client.
- connection ๐
- Low-level single-connection driver.
- error
- Error types for the MQTT tokio client.
- journal
- Session journal: async file writer and replay.
- message
- MQTT v5 message type with full property support.
- options
- Client options with MQTT v5 connect properties and reconnect configuration.
- publish ๐
- Publish builder with MQTT v5 property support.
- subscribe ๐
- Subscribe builder with MQTT v5 option support.
- token
- Tokens for tracking the progress of MQTT operations.
- transport
- Modular transport layer.
Structsยง
- Mqtt
Bytes - A byte slice that satisfies the MQTT v5 Binary Data length limit (at most 65 535 bytes).
- Mqtt
Bytes Buf - Owned binary data that satisfies the MQTT v5 length limit.
- Mqtt
Client - A session-oriented MQTT v5 client.
- MqttStr
- A UTF-8 string that satisfies all MQTT v5 requirements:
- Mqtt
String - An owned UTF-8 string that satisfies all MQTT v5 requirements.
- Packet
Id - MQTT Packet Identifier (ยง2.2.1).
- Publish
Builder - Builder for publishing a message with optional MQTT v5 properties.
- Subscribe
Builder - Builder for subscribing to a topic filter with MQTT v5 options.
- Subscription
Options - Subscription options byte in a SUBSCRIBE payload entry.
- Topic
- A validated, borrowed MQTT topic name.
- Topic
Buf - An owned, validated MQTT topic name.
- Topic
Filter - A validated, borrowed MQTT topic filter.
- Topic
Filter Buf - An owned, validated MQTT topic filter.
Enumsยง
- Topic
Error - Error returned when constructing a
Topic,TopicFilter, or their owned counterparts.