ruststream-rumqttc implements the RustStream broker contract over rumqttc. Handlers, routers, codecs, and middleware come from the framework; this crate supplies the transport - and nothing broker-specific leaks back into the framework.
MQTT 5 is the primary target because two things the framework relies on exist only there: user properties (headers travel natively, no invented envelope) and shared subscriptions (competing consumers are expressible at all).
Features
- A crate-owned connection task. The client exposes a single event loop that must be polled continuously; the crate drives it in a dedicated task that demultiplexes packets into independent per-subscription streams by topic-filter matching, reconnects with exponential backoff (the client itself retries with zero delay, forever), and resubscribes exactly when the broker reports the session gone - all without ever stalling keep-alive traffic. Delivery back-pressure is the protocol's receive-maximum, which bounds unacknowledged deliveries.
- QoS-aware acknowledgement. QoS 1/2 acknowledge through the protocol under manual control (the client completes the QoS 2 handshake); QoS 0 reports
AckError::Unsupportedrather than pretending. MQTT has no negative acknowledgement, sonack(requeue = true)reportsUnsupportedtoo - unacked messages redeliver when a persistent session resumes - andnack(requeue = false)acknowledges. - Shared subscriptions.
MqttTopic::new("jobs").shared("workers")subscribes$share/workers/jobs; the broker splits the stream across the group, and two group members on one connection round-robin locally (they are one wire subscription). - Wildcards as the protocol defines them (
+,#), with messages reporting the real topic they arrived on. - Headers ride user properties; the well-known
content-type,reply-to, andcorrelation-idheaders ride the matching first-class MQTT 5 properties. - Sessions, wills, retained.
clean_start/session_expiryfor persistent sessions,last_willon the broker,retainon the publish policy, TLS with client certificates (tls_ca+tls_client_auth) for managed MQTT services. - In-process test broker (feature
testing).MqttTestBrokerreproduces core routing with no server, implementsruststream::testing::TestableBroker, and passes the framework's conformance suite in process.
Status
Implemented and verified against Eclipse Mosquitto 2 (the framework's conformance lifecycle suite and the integration tests, including shared subscriptions and wildcard demultiplexing, run in CI against it). Tracks the ruststream 0.6 line; the crate itself is not published to crates.io yet. Design and scope are tracked in powersemmi/ruststream#191.
Write a service
use Duration;
use ;
use subscriber;
use ;
use Deserialize;
async
Test it
The testing feature runs handlers against an in-process MQTT stand-in - no server, same routing. Protocol behaviour (QoS handshakes, shared groups, session redelivery, retained messages) is covered by the env-gated live suite instead: just test-brokers starts mosquitto and runs the integration tests plus the framework conformance lifecycle against it.
Layout
ruststream-rumqttc/
├── crates/
│ └── ruststream-rumqttc/ the published crate
│ └── examples/ runnable mqtt_* examples
├── docker-compose.test.yml mosquitto for the live suite
└── Cargo.toml workspace
Contributing
License
Licensed under the Apache-2.0 license.