🦀 MQTT Typed Client
A type-safe async MQTT client built on top of rumqttc
Automatic topic routing and subscription management with compile-time guarantees
✨ Key Features
- Type-safe topic patterns with named parameters and automatic parsing
- Zero-cost abstractions via procedural macros with compile-time validation
- IDE-friendly experience - full autocomplete for topics, parameters, and generated client methods
- Automatic subscription management with intelligent routing and lifecycle handling
- Built-in serialization support for 8+ formats (Bincode, JSON, MessagePack, etc.)
- Efficient message routing with tree-based topic matching and internal caching
- Smart defaults with full configurability when needed
- Memory efficient design with proper resource management
- Automatic reconnection and graceful shutdown
⚠️ MSRV: Rust 1.85.1 (driven by default bincode
serializer; can be lowered with alternative serializers)
🚀 Quick Start
Add to your Cargo.toml
:
[]
= "0.1.0"
use *;
use mqtt_topic;
use ;
use ;
// Define typed topic with automatic parameter extraction
async
📚 Examples
See examples/ - Complete usage examples with source code
000_hello_world.rs
- Basic publish/subscribe with macros001_ping_pong.rs
- Multi-client communication002_configuration.rs
- Advanced client configuration003_hello_world_lwt.rs
- Last Will & Testament004_hello_world_tls.rs
- TLS/SSL connections005_hello_world_serializers.rs
- Custom serializers006_retain_and_clear.rs
- Retained messages007_custom_patterns.rs
- Custom topic patterns008_modular_example.rs
- Modular application structure
Run examples:
📦 Serialization Support
Multiple serialization formats are supported via feature flags:
bincode
- Binary serialization (default, most efficient)json
- JSON serialization (default, human-readable)messagepack
- MessagePack binary formatcbor
- CBOR binary formatpostcard
- Embedded-friendly binary formatron
- Rusty Object Notationflexbuffers
- FlatBuffers FlexBuffersprotobuf
- Protocol Buffers (requires generated types)
Enable additional serializers:
[]
= { = "0.1.0", = ["messagepack", "cbor"] }
Custom serializers can be implemented by implementing the MessageSerializer
trait.
🎯 Topic Pattern Matching
Supports MQTT wildcard patterns with named parameters:
{param}
- Named parameter (equivalent to+
wildcard){param:#}
- Multi-level named parameter (equivalent to#
wildcard)
use mqtt_topic;
// Traditional MQTT wildcards
// matches: home/kitchen/temperature
// Named parameters (recommended)
// matches: home/kitchen/temperature
// Multi-level parameters
// matches: logs/api/v1/users/create
🔧 Advanced Usage: Low-Level API
For cases where you need direct control without macros:
use *;
use ;
use ;
async
🆚 What mqtt-typed-client adds over rumqttc
Publishing:
// rumqttc - manual topic construction and serialization
let sensor_id = "sensor001";
let data = SensorData ;
let topic = format!;
let payload = to_vec?;
client.publish.await?;
// mqtt-typed-client - type-safe, automatic
topic_client.publish.await?;
Subscribing with routing:
// rumqttc - manual pattern matching and dispatching
// while let Ok(event) = eventloop.poll().await {
// if let Event::Incoming(Packet::Publish(publish)) = event {
// if publish.topic.starts_with("sensors/") {
// // Manual topic parsing, manual deserialization...
// } else if publish.topic.starts_with("alerts/") {
// // More manual parsing...
// }
// }
// }
// mqtt-typed-client - automatic routing to typed handlers
let mut sensor_sub = client.sensor_topic.subscribe.await?;
let mut alert_sub = client.alert_topic.subscribe.await?;
select!
📋 For detailed comparison see: docs/COMPARISON_WITH_RUMQTTC.md
📄 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
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
See CONTRIBUTING.md for detailed guidelines.
📖 API Reference
For detailed API documentation, visit docs.rs/mqtt-typed-client.
🔗 See Also
- rumqttc - The underlying MQTT client library
- MQTT Protocol Specification - Official MQTT documentation
- Rust Async Book - Guide to async Rust programming