queen-mq 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/API.md +1116 -0
  2. package/CACHE.md +519 -0
  3. package/DASHBOARD-V3.md +478 -0
  4. package/DASHBOARD.md +382 -0
  5. package/MOD_QUEUE.md +453 -0
  6. package/PARTITION_LOCKING_DESIGN.md +989 -0
  7. package/PLAN.md +707 -0
  8. package/QUERY_ANALSYS.md +72 -0
  9. package/QUEUE_BUS.md +334 -0
  10. package/README.md +1495 -0
  11. package/V2-PLAN.md +236 -0
  12. package/assets/dashboard.png +0 -0
  13. package/dashboard/.vscode/extensions.json +3 -0
  14. package/dashboard/README.md +5 -0
  15. package/dashboard/index.html +14 -0
  16. package/dashboard/package-lock.json +1458 -0
  17. package/dashboard/package.json +25 -0
  18. package/dashboard/public/vite.svg +1 -0
  19. package/dashboard/src/App.vue +29 -0
  20. package/dashboard/src/assets/styles/main.css +908 -0
  21. package/dashboard/src/assets/vue.svg +1 -0
  22. package/dashboard/src/components/cards/MetricCard.vue +298 -0
  23. package/dashboard/src/components/charts/QueueDepthChart.vue +276 -0
  24. package/dashboard/src/components/charts/QueueLagChart.vue +436 -0
  25. package/dashboard/src/components/charts/ThroughputChart.vue +302 -0
  26. package/dashboard/src/components/common/ActivityFeed.vue +251 -0
  27. package/dashboard/src/components/layout/AppHeader.vue +208 -0
  28. package/dashboard/src/components/layout/AppLayout.vue +88 -0
  29. package/dashboard/src/components/layout/AppSidebar.vue +261 -0
  30. package/dashboard/src/main.js +44 -0
  31. package/dashboard/src/router.js +54 -0
  32. package/dashboard/src/services/api.js +187 -0
  33. package/dashboard/src/services/websocket.js +167 -0
  34. package/dashboard/src/utils/constants.js +56 -0
  35. package/dashboard/src/utils/helpers.js +118 -0
  36. package/dashboard/src/views/Analytics.vue +912 -0
  37. package/dashboard/src/views/Dashboard.vue +906 -0
  38. package/dashboard/src/views/Messages.vue +437 -0
  39. package/dashboard/src/views/QueueDetail.vue +501 -0
  40. package/dashboard/src/views/Queues.vue +333 -0
  41. package/dashboard/vite.config.js +30 -0
  42. package/debug-namespace.js +110 -0
  43. package/docs/long-polling.md +159 -0
  44. package/docs/multi-server-cache-solutions.md +185 -0
  45. package/docs/performance-tuning.md +222 -0
  46. package/examples/bus-mode.js +239 -0
  47. package/examples/continuous-consumer-optimized.js +215 -0
  48. package/examples/continuous-consumer.js +159 -0
  49. package/examples/continuous-producer.js +343 -0
  50. package/examples/mixed-mode.js +277 -0
  51. package/examples/multi-server-test.js +305 -0
  52. package/examples/single.js +64 -0
  53. package/examples/smartchat-dealyed.js +42 -0
  54. package/examples/smartchat.js +52 -0
  55. package/examples/test-cache-invalidation.js +119 -0
  56. package/examples/test-cache-multi-server.js +245 -0
  57. package/examples/test-minimal-client.js +112 -0
  58. package/examples/test-queue-creation-policy.js +137 -0
  59. package/init-db.js +20 -0
  60. package/package.json +36 -0
  61. package/src/client/client.js +291 -0
  62. package/src/client/index.js +6 -0
  63. package/src/client/queenClient.js +513 -0
  64. package/src/client/utils/http.js +172 -0
  65. package/src/client/utils/loadBalancer.js +152 -0
  66. package/src/client/utils/retry.js +35 -0
  67. package/src/config.js +215 -0
  68. package/src/database/connection.js +103 -0
  69. package/src/database/poolManager.js +192 -0
  70. package/src/database/schema-v2.sql +214 -0
  71. package/src/managers/eventManager.js +59 -0
  72. package/src/managers/queueManagerOptimized.js +1512 -0
  73. package/src/managers/resourceCache.js +96 -0
  74. package/src/managers/systemEventManager.js +127 -0
  75. package/src/routes/ack.js +26 -0
  76. package/src/routes/analytics.js +812 -0
  77. package/src/routes/configure.js +46 -0
  78. package/src/routes/messages.js +298 -0
  79. package/src/routes/pop.js +85 -0
  80. package/src/routes/push.js +28 -0
  81. package/src/routes/resources.js +296 -0
  82. package/src/server.js +1286 -0
  83. package/src/services/encryptionService.js +82 -0
  84. package/src/services/evictionService.js +131 -0
  85. package/src/services/retentionService.js +129 -0
  86. package/src/services/startupSync.js +35 -0
  87. package/src/test/test.js +4521 -0
  88. package/src/utils/logger.js +44 -0
  89. package/src/utils/uuid.js +5 -0
  90. package/src/websocket/wsServer.js +221 -0
package/V2-PLAN.md ADDED
@@ -0,0 +1,236 @@
1
+ # Queen V2 Architecture Migration Plan
2
+
3
+ ## Overview
4
+ Restructuring the queue system from a rigid 3-tier hierarchy (Namespaces → Tasks → Queues) to a flexible 2-tier system (Queues → Partitions) with optional grouping fields.
5
+
6
+ ## New Data Model
7
+
8
+ ### Core Structure
9
+ ```
10
+ Queues (with optional namespace/task grouping)
11
+ └── Partitions (FIFO ordering)
12
+ └── Messages
13
+ ```
14
+
15
+ ### Key Changes
16
+ 1. **Remove** `namespaces` table
17
+ 2. **Rename** `tasks` table → `queues` table
18
+ 3. **Rename** `queues` table → `partitions` table
19
+ 4. **Add** optional `namespace` and `task` fields to `queues` table for grouping
20
+ 5. **Default Partition**: Each queue automatically gets a "Default" partition
21
+
22
+ ## Database Schema Changes
23
+
24
+ ### 1. Update schema.sql
25
+ - Drop the `namespaces` table
26
+ - Rename and restructure tables:
27
+ ```sql
28
+ -- New queues table (was tasks)
29
+ CREATE TABLE queen.queues (
30
+ id UUID PRIMARY KEY,
31
+ name VARCHAR(255) UNIQUE NOT NULL,
32
+ namespace VARCHAR(255), -- optional grouping
33
+ task VARCHAR(255), -- optional grouping
34
+ created_at TIMESTAMP
35
+ );
36
+
37
+ -- New partitions table (was queues)
38
+ CREATE TABLE queen.partitions (
39
+ id UUID PRIMARY KEY,
40
+ queue_id UUID REFERENCES queen.queues(id),
41
+ name VARCHAR(255) NOT NULL DEFAULT 'Default',
42
+ priority INTEGER DEFAULT 0,
43
+ options JSONB,
44
+ created_at TIMESTAMP,
45
+ UNIQUE(queue_id, name)
46
+ );
47
+
48
+ -- Messages table stays similar, references partitions
49
+ CREATE TABLE queen.messages (
50
+ id UUID PRIMARY KEY,
51
+ partition_id UUID REFERENCES queen.partitions(id),
52
+ -- rest stays the same
53
+ );
54
+ ```
55
+
56
+ ### 2. Update Indexes
57
+ - Adjust all indexes to work with new structure
58
+ - Add indexes for optional namespace/task fields on queues table
59
+ - Maintain performance-critical indexes on messages table
60
+
61
+ ## API Route Changes
62
+
63
+ ### Push Routes
64
+ **Current**: `POST /api/v1/push`
65
+ ```json
66
+ {
67
+ "items": [{
68
+ "ns": "namespace",
69
+ "task": "task",
70
+ "queue": "queue",
71
+ "payload": {}
72
+ }]
73
+ }
74
+ ```
75
+
76
+ **New**: `POST /api/v1/push`
77
+ ```json
78
+ {
79
+ "items": [{
80
+ "queue": "queue",
81
+ "partition": "partition", // optional, defaults to "Default"
82
+ "payload": {}
83
+ }]
84
+ }
85
+ ```
86
+
87
+ ### Pop Routes
88
+ **Current**:
89
+ - `/api/v1/pop/ns/:ns/task/:task/queue/:queue`
90
+ - `/api/v1/pop/ns/:ns/task/:task`
91
+ - `/api/v1/pop/ns/:ns`
92
+
93
+ **New**:
94
+ - `/api/v1/pop/queue/:queue/partition/:partition` - Pop from specific partition
95
+ - `/api/v1/pop/queue/:queue` - Pop from any available partition in queue
96
+ - `/api/v1/pop?namespace=:ns` - Pop from any queue in namespace (optional filter)
97
+ - `/api/v1/pop?task=:task` - Pop from any queue in task (optional filter)
98
+
99
+ ### Configure Routes
100
+ **Current**: `POST /api/v1/configure`
101
+ ```json
102
+ {
103
+ "ns": "namespace",
104
+ "task": "task",
105
+ "queue": "queue",
106
+ "options": {}
107
+ }
108
+ ```
109
+
110
+ **New**: `POST /api/v1/configure`
111
+ ```json
112
+ {
113
+ "queue": "queue",
114
+ "partition": "partition", // optional, defaults to "Default"
115
+ "options": {}
116
+ }
117
+ ```
118
+
119
+ ### Analytics Routes
120
+ **Current**:
121
+ - `/api/v1/analytics/ns/:ns`
122
+ - `/api/v1/analytics/ns/:ns/task/:task`
123
+
124
+ **New**:
125
+ - `/api/v1/analytics/queue/:queue`
126
+ - `/api/v1/analytics?namespace=:ns` - Filter by namespace
127
+ - `/api/v1/analytics?task=:task` - Filter by task
128
+
129
+ ## Code Changes Required
130
+
131
+ ### 1. Database Layer (`src/database/`)
132
+ - [ ] Rewrite `schema.sql` with new structure
133
+ - [ ] Update `connection.js` initialization if needed
134
+
135
+ ### 2. Manager Classes (`src/managers/`)
136
+ - [ ] Update `queueManagerOptimized.js`:
137
+ - [ ] Change `ensureResources()` to handle queue → partition structure
138
+ - [ ] Update `pushMessages()` to default to "Default" partition
139
+ - [ ] Modify `popMessages()` for new partition logic
140
+ - [ ] Adjust `getQueueStats()` for new structure
141
+ - [ ] Update `resourceCache.js`:
142
+ - [ ] Change cache key format from `ns:task:queue` to `queue:partition`
143
+ - [ ] Update `eventManager.js`:
144
+ - [ ] Adjust event paths from `ns/task/queue` to `queue/partition`
145
+
146
+ ### 3. Route Handlers (`src/routes/`)
147
+ - [ ] Update `push.js`:
148
+ - [ ] Remove ns/task requirements
149
+ - [ ] Add partition defaulting logic
150
+ - [ ] Update `pop.js`:
151
+ - [ ] New route parameter structure
152
+ - [ ] Implement "any available partition" logic
153
+ - [ ] Update `configure.js`:
154
+ - [ ] Work with queue/partition instead of ns/task/queue
155
+ - [ ] Update `analytics.js`:
156
+ - [ ] New aggregation logic based on optional namespace/task fields
157
+ - [ ] Update `messages.js`:
158
+ - [ ] Adjust queries for new structure
159
+
160
+ ### 4. Server (`src/server.js`)
161
+ - [ ] Update all route definitions
162
+ - [ ] Adjust URL patterns
163
+ - [ ] Update WebSocket event paths
164
+
165
+ ### 5. Client Library (`src/client/`)
166
+ - [ ] Update `queenClient.js` with new API structure
167
+ - [ ] Adjust method signatures
168
+
169
+ ### 6. WebSocket (`src/websocket/`)
170
+ - [ ] Update event naming and paths
171
+ - [ ] Adjust queue depth updates
172
+
173
+ ## Implementation Order
174
+
175
+ 1. **Database Schema**
176
+ - Create new `schema-v2.sql`
177
+ - Test schema independently
178
+
179
+ 2. **Core Manager Updates**
180
+ - Update `queueManagerOptimized.js` with new logic
181
+ - Update resource caching
182
+ - Update event manager
183
+
184
+ 3. **Route Handlers**
185
+ - Update each route file for new structure
186
+ - Maintain backwards compatibility temporarily if needed
187
+
188
+ 4. **Server Integration**
189
+ - Update `server.js` with new routes
190
+ - Test each endpoint
191
+
192
+ 5. **Client Updates**
193
+ - Update client library
194
+ - Update examples
195
+
196
+ 6. **Frontend Updates**
197
+ - Update API calls in frontend
198
+ - Adjust data structures
199
+
200
+ ## Partition Selection Logic
201
+
202
+ When popping from a queue (without specifying partition):
203
+ 1. Select the partition with the oldest pending message
204
+ 2. Use `ORDER BY created_at ASC` across partitions
205
+ 3. Maintain FIFO within each partition
206
+ 4. Use `FOR UPDATE SKIP LOCKED` for concurrency
207
+
208
+ ## Default Partition Behavior
209
+
210
+ 1. **Auto-creation**: When a queue is created, automatically create a "Default" partition
211
+ 2. **Push behavior**: If no partition specified, use "Default"
212
+ 3. **Pop behavior**: Include "Default" when popping from queue level
213
+
214
+ ## Node
215
+ Always use "nvm use 22 && your node.js command"
216
+
217
+ ## Testing Checklist
218
+
219
+ - [ ] Push to queue with no partition (should use Default)
220
+ - [ ] Push to specific partition
221
+ - [ ] Pop from specific partition
222
+ - [ ] Pop from queue (any partition)
223
+ - [ ] Queue configuration
224
+ - [ ] Partition configuration
225
+ - [ ] Analytics with namespace filtering
226
+ - [ ] Analytics with task filtering
227
+ - [ ] Message acknowledgment
228
+ - [ ] Batch operations
229
+ - [ ] WebSocket events
230
+ - [ ] Long polling
231
+ - [ ] Lease expiration
232
+ - [ ] Performance with multiple partitions
233
+
234
+ ## Migration Notes
235
+
236
+ - No data migration needed (starting fresh)
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["Vue.volar"]
3
+ }
@@ -0,0 +1,5 @@
1
+ # Vue 3 + Vite
2
+
3
+ This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
4
+
5
+ Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).
@@ -0,0 +1,14 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
7
+ <title>Queen Dashboard - Message Queue Management</title>
8
+ <meta name="description" content="Real-time monitoring and management dashboard for Queen Message Queue System">
9
+ </head>
10
+ <body>
11
+ <div id="app"></div>
12
+ <script type="module" src="/src/main.js"></script>
13
+ </body>
14
+ </html>