Complete MQTT v5.0 Platform
๐ A complete MQTT v5.0 platform featuring both high-performance client library AND full-featured broker implementation - pure Rust, zero unsafe code
This project provides everything you need for MQTT v5.0 development:
- Production-ready MQTT v5.0 broker (Mosquitto replacement)
- High-performance client library with AWS IoT compatibility
- Multiple transport support (TCP, TLS, WebSocket)
- Comprehensive testing with network simulation and property-based testing
๐๏ธ Dual Architecture: Client + Broker
Component | Use Case | Key Features |
---|---|---|
MQTT Broker | Run your own MQTT infrastructure | TLS, WebSocket, Authentication, Bridging, Monitoring |
MQTT Client | Connect to any MQTT broker | AWS IoT compatible, Auto-reconnect, Mock testing |
๐ฆ Installation
Library Crate
[]
= "0.4.1"
CLI Tool
๐ Quick Start
Start an MQTT Broker
use ;
async
Connect a Client
use ;
async
๐ Command Line Interface (mqttv5)
Superior CLI tool that replaces mosquitto_pub, mosquitto_sub, and mosquitto with unified ergonomics:
Installation
# Install from crates.io
# Or build from source
Usage Examples
# Start a broker (replaces mosquitto daemon)
# Publish a message (replaces mosquitto_pub)
# Subscribe to topics (replaces mosquitto_sub)
# Smart prompting when arguments are missing
# ? MQTT topic โบ sensors/
# ? Message content โบ Hello World!
# ? Quality of Service level โบ โ 0 (At most once)
Key CLI Advantages
- ๐ฏ Unified interface - One command instead of mosquitto_pub/mosquitto_sub/mosquitto
- ๐ง Smart prompting - Guides users instead of showing walls of help text
- โ Input validation - Catches errors early with helpful suggestions
- ๐ Descriptive flags -
--topic
instead of-t
, with short aliases available - ๐ Interactive & non-interactive - Works great for both humans and scripts
๐ฏ Why This Platform?
โ Production-Ready Broker
- Mosquitto replacement with better performance and memory usage
- Multiple transports: TCP, TLS, WebSocket in a single binary
- Built-in authentication: Username/password, file-based, bcrypt
- Resource monitoring: Connection limits, rate limiting, memory tracking
- Self-contained: No external dependencies (Redis, PostgreSQL, etc.)
โ High-Performance Client
- Pure Rust implementation: No FFI, no unsafe code
- AWS IoT compatibility: Works seamlessly with AWS IoT Core
- Zero-copy operations: Efficient memory usage with BeBytes
- Direct async/await: Clean Rust async patterns
- Comprehensive testing: Property-based tests and network simulation
๐ฆ Broker Features
Core MQTT v5.0 Broker
- โ Full MQTT v5.0 compliance - All packet types, properties, reason codes
- โ Multiple QoS levels - QoS 0, 1, 2 with proper flow control
- โ Session persistence - Clean start, session expiry, message queuing
- โ Retained messages - Persistent message storage and retrieval
- โ Shared subscriptions - Load balancing across multiple clients
- โ Will messages - Last Will and Testament (LWT) support
Transport & Security
- โ TCP transport - Standard MQTT over TCP on port 1883
- โ TLS/SSL transport - Secure MQTT over TLS on port 8883
- โ WebSocket transport - MQTT over WebSocket for browsers/firewalls
- โ Certificate authentication - Client certificate validation
- โ Username/password authentication - File-based user management
Advanced Features
- โ Broker-to-broker bridging - Connect multiple broker instances
- โ Resource monitoring - $SYS topics, connection metrics, rate limiting
- โ Hot configuration reload - Update settings without restart
- โ Storage backends - File-based or in-memory persistence
- โ ACL (Access Control Lists) - Fine-grained topic permissions
Performance & Scalability
- โ High concurrency - Handle 10,000+ concurrent connections
- โ Connection pooling - Efficient resource reuse
- โ Optimized routing - Fast topic matching and message delivery
- โ Memory monitoring - Prevent resource exhaustion attacks
- โ Rate limiting - Per-client message and bandwidth limits
๐ฆ Client Features
Core MQTT v5.0 Client
- โ Full MQTT v5.0 protocol compliance - All MQTT 5.0 features implemented
- โ Callback-based message handling - Simple, intuitive API with automatic message routing
- โ
AWS IoT SDK Compatible - Subscribe returns
(packet_id, qos)
like Python paho-mqtt - โ Automatic reconnection - Built-in exponential backoff and session recovery
- โ Client-side message queuing - Handles offline scenarios gracefully
Transport & Connectivity
- โ Certificate loading from bytes - Load TLS certificates from memory (PEM/DER formats)
- โ WebSocket transport - MQTT over WebSocket for browsers and firewall-restricted environments
- โ TLS/SSL support - Secure connections with certificate validation
- โ Session persistence - Survives disconnections with clean_start=false
Testing & Development
- โ
Mockable Client Interface -
MqttClientTrait
enables testing without real brokers - โ Comprehensive property testing - 29 property-based tests ensuring robustness
- โ Flow control - Respects broker receive maximum limits
- โ Zero-copy message handling - Efficient memory usage with BeBytes
๐ฆ Advanced Broker Configuration
Multi-Transport Broker
use ;
async
Broker with Authentication
use ;
async
Broker Bridging
use ;
use QoS;
// Connect two brokers together
let bridge_config = new
// Forward sensor data from edge to cloud
.add_topic
// Receive commands from cloud to edge
.add_topic
// Bidirectional health monitoring
.add_topic;
// Add bridge to broker (broker handles connection management)
// broker.add_bridge(bridge_config).await?;
๐งช Testing Support
Unit Testing with Mock Client
use ;
async
// Your production code uses the trait
async
โ๏ธ AWS IoT Support
The client library includes AWS IoT compatibility features:
use ;
use Duration;
// AWS IoT endpoint detection and connection handling
let client = new;
// Connect to AWS IoT endpoint (automatically detects AWS IoT and optimizes connection)
client.connect.await?;
// Subscribe returns (packet_id, qos) tuple for compatibility
let = client.subscribe.await?;
// AWS IoT topic validation prevents publishing to reserved topics
use NamespaceValidator;
let validator = aws_iot.with_device_id;
// This will succeed - device can update its own shadow
client.publish.await?;
// This will be rejected - device cannot publish to shadow response topics
// client.publish("$aws/things/device-123/shadow/update/accepted", data).await?; // Error!
Key AWS IoT features:
- Endpoint detection: Automatically detects AWS IoT endpoints and optimizes connection behavior
- Topic validation: Built-in validation for AWS IoT topic restrictions and limits
- ALPN support: TLS configuration with AWS IoT ALPN protocol support
- Certificate loading: Load client certificates from bytes (PEM/DER formats)
- SDK compatibility: Subscribe method returns
(packet_id, qos)
tuple like other AWS SDKs
๐ ๏ธ Development & Building
Prerequisites
- Rust 1.82 or later
- cargo-make (
cargo install cargo-make
)
Quick Setup
# Clone the repository
# Install development tools and git hooks
# Run all CI checks locally (MUST pass before pushing)
Available Commands
# Development
# CI/CD
# Examples (use raw cargo for specific targets)
# Benchmarks (use raw cargo for specific targets)
Testing
# Generate test certificates (required for TLS tests)
# Run unit tests (fast)
# Run all tests including integration tests
# Run specific test suites (use raw cargo for specific targets)
๐๏ธ Architecture
This project follows modern Rust async patterns:
Design Principles
- Direct async methods for all operations (no indirection)
- Shared state via
Arc<RwLock<T>>
(no message passing) - Zero-copy operations where possible
- Resource efficiency with connection pooling and buffer reuse
๐ Performance
The broker is designed for high performance:
- 10,000+ concurrent connections on modest hardware
- Low memory footprint with connection pooling
- Fast topic matching with optimized routing algorithms
- Zero-copy message processing where possible
- Comprehensive benchmarking suite for performance validation
๐ Security
Security is built-in, not bolted-on:
- TLS 1.2+ support with certificate validation
- Username/password authentication with bcrypt hashing
- Access Control Lists (ACL) for fine-grained permissions
- Rate limiting to prevent DoS attacks
- Resource monitoring to prevent resource exhaustion
- Client certificate authentication for mutual TLS
๐ License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
๐ Documentation
- Architecture Overview - System design and principles
- Broker Configuration - Complete config reference
- Authentication Guide - Security setup
- Deployment Guide - Production deployment
- API Documentation - Complete API reference
Built with โค๏ธ in Rust. One reliable state machine.