Skip to main content

rmqtt/
lib.rs

1#![deny(unsafe_code)] // Enforce memory safety across the entire crate
2#![recursion_limit = "256"] // Allow deeper recursion for complex macros
3
4//! RMQTT Broker Core Implementation (v2025.04)  
5//!  
6//! Implements high-performance MQTT broker architecture with full protocol compliance (v3.1.1 & v5.0),  
7//! designed for mission-critical IoT systems and large-scale distributed deployments. Key features:  
8//!  
9//! 1. **Protocol Engine**  
10//!    - Dual-stack MQTT v3/v5 support via `v3`/`v5` modules  
11//!    - Zero-copy codec implementation from `rmqtt_codec`  
12//!    - QoS 0/1/2 message handling with `inflight` tracking  
13//!
14//!  
15//! 2. **Enterprise Features**  
16//!    - Distributed session management via `shared` module  
17//!    - Cluster node coordination in `node` module  
18//!    - TLS/SSL support with certificate validation  
19//!    - Retained message store (`retain` feature)  
20//!  
21//! 3. **Extensibility**  
22//!    - Plugin system architecture (`plugin` module)  
23//!    - Custom authentication hooks (`acl` module)  
24//!    - Metrics collection pipeline (`metrics` feature)  
25//!
26//!  
27//! [MQTT Spec Compliance](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html)  
28//!
29//! # Overall Example
30//! ```rust,no_run
31//!
32//! use rmqtt::context::ServerContext;
33//! use rmqtt::net::{Builder, Result};
34//! use rmqtt::server::MqttServer;
35//!
36//! #[tokio::main]
37//! async fn main() -> Result<()> {
38//!    
39//!    let scx = ServerContext::new().build().await;
40//!
41//!    MqttServer::new(scx)
42//!       .listener(Builder::new().name("external/tcp").laddr(([0, 0, 0, 0], 1883).into()).bind()?.tcp()?)
43//!       .listener(Builder::new().name("internal/tcp").laddr(([0, 0, 0, 0], 11883).into()).bind()?.tcp()?)
44//!       .listener(Builder::new().name("external/ws").laddr(([0, 0, 0, 0], 8080).into()).bind()?.ws()?)
45//!       .build()
46//!       .run()
47//!       .await?;
48//!       Ok(())
49//! }
50//!
51//! ```
52
53pub mod acl; // Access Control List management
54pub mod args; // Command-line argument parsing
55pub mod context; // Shared execution context
56
57// Feature-gated Modules
58#[cfg(feature = "delayed")] // Delayed message publishing
59pub mod delayed;
60#[cfg(feature = "grpc")] // gRPC API integration
61pub mod grpc;
62#[cfg(feature = "msgstore")] // Message storage subsystem
63pub mod message;
64#[cfg(feature = "metrics")] // Metrics collection and reporting
65pub mod metrics;
66#[cfg(feature = "plugin")] // Plugin system infrastructure
67pub mod plugin;
68#[cfg(feature = "retain")] // Retained message handling
69pub mod retain;
70#[cfg(feature = "stats")] // Runtime statistics tracking
71pub mod stats;
72
73// Essential Services
74pub mod executor; // Async task executor
75pub mod extend; // Extension points
76pub mod fitter; // Message fitting strategies
77pub mod hook; // Event hook system
78pub mod inflight; // In-flight message tracking
79pub mod node; // Cluster node management
80pub mod queue; // Message queue implementation
81pub mod router; // Message routing core
82pub mod server; // Server lifecycle management
83pub mod session; // Client session handling
84pub mod shared; // Shared state management
85
86// Subscription Management
87#[cfg(any(feature = "auto-subscription", feature = "shared-subscription"))]
88pub mod subscribe; // Subscription services
89
90// Topic Handling
91pub mod topic; // Topic parsing and validation
92pub mod trie; // Topic trie structure
93
94// Protocol Support
95pub mod types; // Common data types
96pub mod v3; // MQTT v3.1.1 implementation
97pub mod v5; // MQTT v5.0 implementation
98
99/// External Crate Re-exports
100pub use net::{Error, Result}; // Network error types
101
102/// Feature-gated Re-exports
103pub use rmqtt_codec as codec; // MQTT protocol codec
104#[cfg(any(feature = "metrics", feature = "plugin"))] // Macro utilities
105pub use rmqtt_macros as macros;
106pub use rmqtt_net as net; // Network abstractions
107pub use rmqtt_utils as utils; // Common utilities