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
//! # Quetty Server Library
//!
//! Core server-side functionality for the Quetty Azure Service Bus terminal application.
//! This crate provides comprehensive Azure Service Bus integration, authentication,
//! message processing, and bulk operations capabilities.
//!
//! ## Architecture Overview
//!
//! The server library is organized into several key modules:
//!
//! - **[`auth`]** - Authentication system supporting Azure AD and connection strings
//! - **[`service_bus_manager`]** - Core Service Bus operations and management
//! - **[`producer`]** and **[`consumer`]** - Message production and consumption
//! - **[`bulk_operations`]** - Efficient bulk message processing
//! - **[`model`]** - Data models and message representations
//! - **[`taskpool`]** - Thread pool management for concurrent operations
//! - **[`utils`]** - Utility functions and helpers
//!
//! ## Key Features
//!
//! ### Multi-Modal Authentication
//! - **Azure Active Directory** - Device Code Flow and Client Credentials
//! - **Connection Strings** - SAS token-based authentication
//! - **Token Management** - Automatic refresh and caching
//!
//! ### High-Performance Message Processing
//! - **Concurrent Operations** - Multi-threaded message processing
//! - **Bulk Operations** - Efficient batch send/delete operations
//! - **Resource Management** - Automatic connection pooling and cleanup
//!
//! ### Azure Integration
//! - **Management API** - Namespace and queue discovery
//! - **Service Bus Operations** - Send, receive, peek, delete messages
//! - **Queue Statistics** - Real-time metrics and monitoring
//!
//! ## Quick Start
//!
//! ### Basic Service Bus Operations
//! ```no_run
//! use quetty_server::service_bus_manager::ServiceBusManager;
//! use quetty_server::auth::ConnectionStringProvider;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Initialize authentication
//! let auth_provider = ConnectionStringProvider::new(connection_config)?;
//!
//! // Create Service Bus manager
//! let manager = ServiceBusManager::new(auth_provider).await?;
//!
//! // Send a message
//! let message_id = manager.send_message(
//! "my-queue",
//! "Hello, Service Bus!".to_string(),
//! None
//! ).await?;
//!
//! println!("Message sent with ID: {}", message_id);
//! Ok(())
//! }
//! ```
//!
//! ### Bulk Operations
//! ```no_run
//! use quetty_server::bulk_operations::BulkOperationHandler;
//! use quetty_server::service_bus_manager::ServiceBusManager;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let manager = ServiceBusManager::new(auth_provider).await?;
//! let bulk_handler = BulkOperationHandler::new(manager);
//!
//! // Bulk send messages
//! let messages = vec![
//! "Message 1".to_string(),
//! "Message 2".to_string(),
//! "Message 3".to_string(),
//! ];
//!
//! let results = bulk_handler.bulk_send("my-queue", messages).await?;
//! println!("Sent {} messages", results.len());
//! Ok(())
//! }
//! ```
//!
//! ### Authentication with Azure AD
//! ```no_run
//! use quetty_server::auth::{AzureAdProvider, AuthStateManager};
//! use std::sync::Arc;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Initialize Azure AD authentication
//! let auth_state = Arc::new(AuthStateManager::new());
//! let azure_provider = AzureAdProvider::new(azure_config, http_client)?;
//!
//! // Authenticate and get token
//! let token = azure_provider.authenticate().await?;
//! println!("Authenticated successfully");
//! Ok(())
//! }
//! ```
//!
//! ## Integration with UI
//!
//! This server library is designed to work seamlessly with the Quetty UI:
//!
//! - **Shared Authentication State** - Synchronized auth across UI and server
//! - **Async Operations** - Non-blocking operations for responsive UI
//! - **Error Propagation** - Structured error handling for UI feedback
//! - **Progress Reporting** - Real-time operation progress for bulk operations
//!
//! ## Performance Considerations
//!
//! - **Connection Pooling** - Efficient Service Bus client management
//! - **Concurrent Operations** - Parallel processing where possible
//! - **Memory Management** - Careful resource cleanup and disposal
//! - **Batch Processing** - Optimized bulk operations for large datasets
//!
//! ## Error Handling
//!
//! The library provides comprehensive error handling with detailed error types:
//!
//! - **Authentication Errors** - Token issues, expired credentials
//! - **Service Bus Errors** - Network issues, quota exceeded, invalid operations
//! - **Validation Errors** - Input validation and constraint violations
//! - **Resource Errors** - Connection failures, timeout issues