ruststream-rumqttc connects a RustStream service to an MQTT 5 broker over
rumqttc. Handlers, routing, codecs and middleware come from
the framework; this crate is the transport.
Features
- A connection task the crate owns: one event loop per broker, per-subscription streams, reconnects with backoff and resubscribes when the session is gone.
- QoS-aware acknowledgement for QoS 1 and 2; QoS 0 reports that it has none.
- Shared subscriptions for competing consumers.
- Overlapping filters on one connection, each receiving a message once (MQTT 5 subscription identifiers); the same filter opened twice is one wire subscription.
- Topics and filters:
MqttTopicfor a topic,MqttFilterfor the+and#wildcards. - Retry caps and dead-letter topics declared where the handler is mounted.
- Batches assembled on the client.
- Headers as user properties, with
content-type,reply-toandcorrelation-idas the native MQTT 5 properties. - Byte payloads without a codec:
#[derive(Serialized)]out,#[derive(Deserialized)]in. - Sessions, wills and retained messages, QoS and retain per message
(
publisher.message(&state).retain(true).publish()), and TLS with client certificates. - AsyncAPI with the specification's
mqttbinding, behind theasyncapifeature. - Tests run the production app (feature
testing):TestApp::start(app())connectsMqttBrokerin process, with no server;TestApp::start_live(app())runs the same test against a real broker.
Install
[]
= { = "0.7", = ["macros", "json"] }
= "0.7"
= { = "1", = ["derive"] }
[]
= { = "0.7", = ["testing"] }
Write a service
use Duration;
use *;
use ;
async
#[ruststream::app] generates main, so the binary understands run and asyncapi gen.
Test it
TestApp runs the service's own app with MqttBroker in process, with no server.
TestApp::start_live(app()) runs the same test against a real broker.
use TestApp;
let tb = start.await?;
tb.
.message
.to
.publish
.await?;
tb.
.
.assert_called_once
.with;
tb.shutdown.await?;
Documentation
- Getting started - installation and a first service against a local Mosquitto.
- Guides - topics and share groups, delivery guarantees, device state, publishing commands, retries, request and response, testing and a production server.
- Components - one page per part of the crate: the broker, subscriptions, settlement, the context, publishing, AsyncAPI and testing.
- Architecture - how the crate sits between
rumqttcand the runtime. - Benchmarks - what the crate costs over the raw client.
- API reference - every item on docs.rs.
- The framework: https://powersemmi.github.io/ruststream/latest/
Minimum supported Rust version
The MSRV is 1.95, edition 2024.
Contributing
See CONTRIBUTING.md.
License
Licensed under the Apache-2.0 license.