[−][src]Crate mosquitto_rs
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:
vendored-mosquitto
- use bundled libmosquitto 2.4 library. 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.
Structs
Client | A high-level, asynchronous mosquitto MQTT client |
ConnectionStatus | Represents the status of the connection attempt.
The embedded status code value depends on the protocol version
that was setup for the client.
For MQTT v5.0, look at section 3.2.2.2 Connect Reason code: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html
For MQTT v3.1.1, look at section 3.2.2.3 Connect Return code: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html
Use the |
LibraryVersion | Represents the version of the linked mosquitto client library |
Message | Represents a received message that matches one or more of the subscription topic patterns on a client. |
Mosq |
|
Enums
ClientOption | |
Error | |
ProtocolVersion | |
QoS |
Traits
Callbacks | Defines handlers that can be used to determine when various functions have completed. |
Functions
lib_version | Returns the version information for the linked mosquitto library |
Type Definitions
MessageId | Represents an individual message identifier. This is used in this client to determine when a message has been sent. |
PasswdCallback | An OpenSSL password callback (see |