Skip to main content

Crate pamoja_mqtt

Crate pamoja_mqtt 

Source
Expand description

MQTT transport for the pamoja SDK.

MqttTransport implements the core [Transport] trait 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.

§Examples

use pamoja_core::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§

Message
A message received from a subscribed topic.
MqttConfig
Connection settings for an MqttTransport.
MqttTransport
An MQTT client that implements the core [Transport] trait.

Enums§

QualityOfService
The delivery guarantee applied to published and subscribed messages.