server/service_bus_manager/commands.rs
1use super::types::{MessageData, QueueType};
2use crate::bulk_operations::MessageIdentifier;
3
4/// Commands for Service Bus operations using the command pattern.
5///
6/// This enum defines all possible operations that can be performed through the
7/// [`ServiceBusManager`]. Each command encapsulates the parameters needed for
8/// a specific operation, providing a clean separation between the command
9/// definition and its execution.
10///
11/// # Command Categories
12///
13/// - **Queue Management** - Switch queues, get statistics, and manage connections
14/// - **Message Retrieval** - Peek and receive messages from queues
15/// - **Individual Message Operations** - Complete, abandon, or dead letter single messages
16/// - **Bulk Operations** - Efficient bulk processing of multiple messages
17/// - **Send Operations** - Send single or multiple messages to queues
18/// - **Status Operations** - Check connection health and queue statistics
19/// - **Resource Management** - Clean up consumers and reset connections
20///
21/// # Examples
22///
23/// ```no_run
24/// use quetty_server::service_bus_manager::{ServiceBusCommand, QueueType};
25///
26/// // Switch to a queue
27/// let command = ServiceBusCommand::SwitchQueue {
28/// queue_name: "my-queue".to_string(),
29/// queue_type: QueueType::Queue,
30/// };
31///
32/// // Peek messages
33/// let command = ServiceBusCommand::PeekMessages {
34/// max_count: 10,
35/// from_sequence: None,
36/// };
37///
38/// // Send a message
39/// let command = ServiceBusCommand::SendMessage {
40/// queue_name: "target-queue".to_string(),
41/// message: message_data,
42/// };
43/// ```
44#[derive(Debug, Clone)]
45pub enum ServiceBusCommand {
46 /// Switch to a different queue for message operations.
47 ///
48 /// Changes the active queue context for subsequent operations.
49 SwitchQueue {
50 /// Name of the queue to switch to
51 queue_name: String,
52 /// Type of queue (Queue or Topic)
53 queue_type: QueueType,
54 },
55
56 /// Get information about the currently active queue.
57 GetCurrentQueue,
58
59 /// Retrieve detailed statistics for a specific queue.
60 ///
61 /// Returns message counts, size information, and other queue metrics.
62 GetQueueStatistics {
63 /// Name of the queue to get statistics for
64 queue_name: String,
65 /// Type of queue (Queue or Topic)
66 queue_type: QueueType,
67 },
68
69 /// Peek at messages without removing them from the queue.
70 ///
71 /// Messages remain in the queue and can be retrieved again.
72 PeekMessages {
73 /// Maximum number of messages to peek
74 max_count: u32,
75 /// Optional sequence number to start peeking from
76 from_sequence: Option<i64>,
77 },
78
79 /// Receive messages with a lock for processing.
80 ///
81 /// Messages are locked during processing and must be completed or abandoned.
82 ReceiveMessages {
83 /// Maximum number of messages to receive
84 max_count: u32,
85 },
86
87 /// Complete (acknowledge) a message, removing it from the queue.
88 CompleteMessage {
89 /// ID of the message to complete
90 message_id: String,
91 },
92
93 /// Abandon a message, returning it to the queue for redelivery.
94 AbandonMessage {
95 /// ID of the message to abandon
96 message_id: String,
97 },
98
99 /// Move a message to the dead letter queue.
100 ///
101 /// Used for messages that cannot be processed successfully.
102 DeadLetterMessage {
103 /// ID of the message to dead letter
104 message_id: String,
105 /// Optional reason for dead lettering
106 reason: Option<String>,
107 /// Optional detailed error description
108 error_description: Option<String>,
109 },
110
111 /// Complete multiple messages in a single bulk operation.
112 BulkComplete {
113 /// List of message identifiers to complete
114 message_ids: Vec<MessageIdentifier>,
115 },
116
117 /// Delete multiple messages efficiently using bulk processing.
118 ///
119 /// Optimized for large-scale message deletion operations.
120 BulkDelete {
121 /// List of message identifiers to delete
122 message_ids: Vec<MessageIdentifier>,
123 /// Maximum position to scan when looking for messages
124 max_position: usize,
125 },
126
127 /// Abandon multiple messages in a single bulk operation.
128 BulkAbandon {
129 /// List of message identifiers to abandon
130 message_ids: Vec<MessageIdentifier>,
131 },
132
133 /// Move multiple messages to the dead letter queue.
134 BulkDeadLetter {
135 /// List of message identifiers to dead letter
136 message_ids: Vec<MessageIdentifier>,
137 /// Optional reason for dead lettering
138 reason: Option<String>,
139 /// Optional detailed error description
140 error_description: Option<String>,
141 },
142
143 /// Send multiple messages to a target queue with optional source deletion.
144 ///
145 /// Can optionally delete source messages after successful send.
146 BulkSend {
147 /// List of message identifiers to send
148 message_ids: Vec<MessageIdentifier>,
149 /// Name of the target queue to send messages to
150 target_queue: String,
151 /// Whether to delete source messages after sending
152 should_delete_source: bool,
153 /// Number of times to repeat each message
154 repeat_count: usize,
155 /// Maximum position to scan when retrieving messages
156 max_position: usize,
157 },
158
159 /// Send pre-fetched message data to a target queue.
160 ///
161 /// Used when message content has already been retrieved via peek operations.
162 BulkSendPeeked {
163 /// Pre-fetched message data (identifier and content)
164 messages_data: Vec<(MessageIdentifier, Vec<u8>)>,
165 /// Name of the target queue to send messages to
166 target_queue: String,
167 /// Number of times to repeat each message
168 repeat_count: usize,
169 },
170
171 /// Send a single message to a specific queue.
172 SendMessage {
173 /// Name of the target queue
174 queue_name: String,
175 /// Message data to send
176 message: MessageData,
177 },
178
179 /// Send multiple messages to a specific queue.
180 SendMessages {
181 /// Name of the target queue
182 queue_name: String,
183 /// List of messages to send
184 messages: Vec<MessageData>,
185 },
186
187 /// Check the current connection status to Service Bus.
188 GetConnectionStatus,
189
190 /// Get basic statistics for a specific queue.
191 GetQueueStats {
192 /// Name of the queue to get stats for
193 queue_name: String,
194 },
195
196 /// Dispose of the current message consumer.
197 ///
198 /// Cleans up consumer resources and releases locks.
199 DisposeConsumer,
200
201 /// Dispose of all Service Bus resources.
202 ///
203 /// Comprehensive cleanup of all consumers, producers, and connections.
204 DisposeAllResources,
205
206 /// Reset the Service Bus connection.
207 ///
208 /// Re-establishes connection using current configuration.
209 ResetConnection,
210}