Skip to main content

Crate pamoja_mqtt

Crate pamoja_mqtt 

Source
Expand description

MQTT transport for the pamoja SDK.

MqttTransport implements the core [Transport] and [Receive] traits on top of the pure-Rust [rumqttc] client, so an application can publish to and subscribe from an MQTT broker through the same protocol-agnostic surface it uses for every other transport.

Once connect succeeds the transport owns a background task that drives the MQTT event loop: it answers keep-alive pings, completes delivery handshakes, and forwards inbound messages to an internal queue that recv drains. Publishing and subscribing use the default QualityOfService configured on the transport.

The client speaks MQTT 3.1.1 with a clean session, so a connection starts with no subscriptions and a reconnect places them again. Topics and filters are checked against the rules of the OASIS MQTT 3.1.1 standard, section 4.7, before anything is sent, and a message too large for the connection’s packet limit is refused rather than ending the connection.

Beyond send, publish takes the quality of service and retain flag of one message and returns a Delivery that settles when the broker acknowledges it. A configuration can carry a username and password, a last-will message the broker publishes if the client drops off without saying goodbye, and, with the default tls feature, Tls settings for a broker on port 8883.

§Examples

use pamoja_core::{Receive, Transport};
use pamoja_mqtt::{MqttConfig, MqttTransport};

let mut transport = MqttTransport::new(MqttConfig::new("sensor-1", "localhost", 1883));
transport.connect().await?;
transport.subscribe("sensors/+/temperature").await?;
transport.send("sensors/1/temperature", b"21.5").await?;

if let Some(message) = transport.recv().await? {
    println!("{}: {} bytes", message.topic, message.payload.len());
}

Structs§

Delivery
The broker’s acknowledgment of one published message, still to come.
Inbox
The messages arriving on a transport’s connection, readable apart from the transport.
Message
A message that arrived on a subscribed topic.
MqttConfig
Connection settings for an MqttTransport.
MqttTransport
An MQTT client that implements the core [Transport] and [Receive] traits.
PublishOptions
How one message is published: its quality of service, and whether the broker keeps it.
Tls
How a connection to the broker is secured.
Will
A message the broker publishes on the client’s behalf if the client’s connection ends without a DISCONNECT: the network dropped, the power failed, or the keep-alive ran out.

Enums§

QualityOfService
The delivery guarantee applied to published and subscribed messages.

Constants§

DEFAULT_MAX_PACKET_SIZE
The largest packet a connection sends or accepts unless configured otherwise, in bytes.