1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//! MQTT Subscription Management Core
//!
//! Provides extensible subscription handling implementations supporting MQTT 5.0 protocol
//! features with asynchronous execution and cluster-aware operations. The implementation
//! follows EMQX-style design patterns for shared subscriptions.
//!
//! ## Core Components
//! 1. **Shared Subscription System**:
//! - Implements random selection strategy for subscriber load balancing (default)
//! - Supports online status detection through router integration
//! - Enables distributed session management across nodes
//!
//! 2. **Auto-Subscription Framework**:
//! - Provides trait-based extensibility for dynamic subscription rules
//! - Supports conditional compilation via feature flags
//!
//! ## Key Design Features
//! - **Asynchronous Architecture**:
//! ```rust,ignore
//! #[async_trait] // Transforms async methods into boxed futures
//! ```
//! Uses `async-trait` macro to enable async methods in traits while maintaining object safety
//! through `Pin<Box<dyn Future>>` returns
//!
//! - **Cluster Optimization**:
//! - Node-aware subscriber selection with fallback mechanisms
//! - Online status caching to reduce router queries
//!
//! - **Extensibility**:
//! ```rust,ignore
//! #[cfg(feature = "shared-subscription")] // Feature-gated implementation
//! ```
//! Modular design allows optional inclusion of advanced subscription types
//!
//! ## Implementation Notes
//! 1. **Shared Subscription Workflow**:
//! - Filters candidates through `is_supported()` config check
//! - Performs online status validation via `router().is_online()`
//! - Implements random selection with retry logic for offline nodes
//!
//! 2. **Performance Considerations**:
//! - Uses `#[inline]` hints for hot path methods
//! - Avoids unnecessary cloning through reference counting
//! - Limits dynamic dispatch through concrete trait implementations
//!
//! The architecture balances protocol compliance (MQTT 5.0 spec) with practical performance
//! requirements, leveraging Rust's type system for safe concurrent operations.
use async_trait;
use crateServerContext;
use crate*;
/// Defines the shared subscription selection strategy for a cluster node.
///
/// Implementations control how subscribers within a shared subscription group
/// (`$share/{group}/{topic}`) are selected. The default implementation uses
/// a round-robin selection strategy with online status filtering.
///
/// # Context Parameters
///
/// The `choice` method provides the following context for strategy decisions:
/// - `group`: the shared subscription group name (e.g. `"group1"` in `$share/group1/topic`)
/// - `publisher_id`: the publishing client's identity (contains `node_id` and `client_id`)
/// - `topic`: the published topic name used for topic-based hashing
/// Default shared subscription implementation using round-robin selection.
///
/// Note: This is a best-effort single-node round-robin. For true round-robin
/// across cluster nodes, use the `rmqtt-shared-subscription` plugin.
;
/// Defines auto-subscription behavior for newly connected clients.
///
/// Implementations specify which topics a client should be automatically
/// subscribed to upon connection. This is useful for system topics or
/// mandatory monitoring subscriptions.
/// Default auto-subscription implementation that performs no automatic subscriptions.
///
/// All methods return their default (no-op) values: `enable()` returns `false`
/// and `subscribes()` returns an empty vector.
;