vs-queue 0.1.0__py3-none-any.whl
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.
- vs_queue/__init__.py +6 -0
- vs_queue/base/__init__.py +0 -0
- vs_queue/base/vs_base_consumer.py +25 -0
- vs_queue/base/vs_base_queue.py +38 -0
- vs_queue/decorator/__init__.py +0 -0
- vs_queue/decorator/vs_queue_listener.py +38 -0
- vs_queue/factory/__init__.py +0 -0
- vs_queue/factory/vs_queue_factory.py +18 -0
- vs_queue/manager/__init__.py +0 -0
- vs_queue/manager/vs_queue_manager.py +116 -0
- vs_queue/provider/__init__.py +0 -0
- vs_queue/provider/vs_rabbitmq_queue.py +91 -0
- vs_queue/provider/vs_redis_queue.py +104 -0
- vs_queue/registry/__init__.py +0 -0
- vs_queue/registry/vs_queue_registry.py +24 -0
- vs_queue/retry/__init__.py +0 -0
- vs_queue/retry/vs_retry_policy.py +30 -0
- vs_queue/schema/__init__.py +0 -0
- vs_queue/schema/vs_message.py +13 -0
- vs_queue-0.1.0.dist-info/METADATA +978 -0
- vs_queue-0.1.0.dist-info/RECORD +23 -0
- vs_queue-0.1.0.dist-info/WHEEL +5 -0
- vs_queue-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,978 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vs-queue
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Pluggable async message queue library for Viveka Sutra — Redis Streams, RabbitMQ, retry, dead letter, and annotation-based consumers
|
|
5
|
+
Project-URL: Homepage, https://vivekasutra.com/
|
|
6
|
+
Project-URL: Source, https://github.com/vivekasutra/viveka-mula
|
|
7
|
+
Keywords: queue,messaging,redis,rabbitmq,async,consumer,viveka,vs
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: Other/Proprietary License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
16
|
+
Classifier: Framework :: AsyncIO
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: pydantic>=2.0
|
|
21
|
+
Provides-Extra: redis
|
|
22
|
+
Requires-Dist: redis>=5.0; extra == "redis"
|
|
23
|
+
Requires-Dist: hiredis>=2.0; extra == "redis"
|
|
24
|
+
Provides-Extra: rabbitmq
|
|
25
|
+
Requires-Dist: aio-pika>=9.0; extra == "rabbitmq"
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: build; extra == "dev"
|
|
28
|
+
Requires-Dist: twine; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
31
|
+
|
|
32
|
+
# vs-queue
|
|
33
|
+
|
|
34
|
+
Pluggable async message queue library for Viveka Sutra — Redis Streams, RabbitMQ, retry policies, dead letter queues, and annotation-based consumers.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Overview
|
|
39
|
+
|
|
40
|
+
`vs-queue` is the messaging backbone for all Viveka Sutra services. It provides a unified API for publishing and consuming messages across multiple queue backends. Services publish a `VsMessage` to a named queue and consumers process it — the queue backend is swappable via config without changing application code.
|
|
41
|
+
|
|
42
|
+
Key features:
|
|
43
|
+
- Unified `VsBaseQueue` abstraction — swap Redis for RabbitMQ without changing consumer code
|
|
44
|
+
- `@queue_listener` decorator — register consumers declaratively, like Spring's `@RabbitListener`
|
|
45
|
+
- `VsQueueManager` — lifecycle management for all consumers: start, stop, health check
|
|
46
|
+
- Built-in retry with exponential backoff
|
|
47
|
+
- Dead letter queue (DLQ) support
|
|
48
|
+
- Registry pattern — register custom queue providers by name
|
|
49
|
+
- Fully async — built on `asyncio`, compatible with FastAPI and any async framework
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## The Problem It Solves
|
|
54
|
+
|
|
55
|
+
Services that call each other directly over HTTP are tightly coupled — a slow or unavailable downstream service blocks the caller.
|
|
56
|
+
|
|
57
|
+
### Without vs-queue
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
# Caller blocks waiting for the downstream service
|
|
61
|
+
response = await http_client.post("/v1/process", json=payload)
|
|
62
|
+
response.raise_for_status()
|
|
63
|
+
return response.json()
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If the downstream service is slow or down, every caller fails. There is no retry, no buffering, and no way to recover without restarting.
|
|
67
|
+
|
|
68
|
+
### With vs-queue
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
# Caller publishes and returns immediately
|
|
72
|
+
await queue.publish("orchestrator:tasks", VsMessage(payload={"node_id": node_id}))
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The consumer processes at its own pace. If processing fails it retries automatically. If it exceeds max retries it goes to the dead letter queue for inspection. The caller never blocks.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install vs-queue
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
With Redis Streams support:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install vs-queue[redis]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
With RabbitMQ support:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pip install vs-queue[rabbitmq]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Both backends:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
pip install vs-queue[redis,rabbitmq]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Dependencies
|
|
106
|
+
|
|
107
|
+
| Package | Version | Required | Purpose |
|
|
108
|
+
|---|---|---|---|
|
|
109
|
+
| `pydantic` | `>=2.0` | Yes | `VsMessage` schema validation |
|
|
110
|
+
| `redis` | `>=5.0` | No — install with `[redis]` extra | Redis Streams backend |
|
|
111
|
+
| `hiredis` | `>=2.0` | No — install with `[redis]` extra | Redis protocol parser (performance) |
|
|
112
|
+
| `aio-pika` | `>=9.0` | No — install with `[rabbitmq]` extra | RabbitMQ backend via AMQP |
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Quick Start
|
|
117
|
+
|
|
118
|
+
### Publisher
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
import asyncio
|
|
122
|
+
from vs_queue import VsQueueRegistry # auto-registers redis and rabbitmq
|
|
123
|
+
from vs_queue.factory.vs_queue_factory import VsQueueFactory
|
|
124
|
+
from vs_queue.schema.vs_message import VsMessage
|
|
125
|
+
|
|
126
|
+
async def main():
|
|
127
|
+
queue = VsQueueFactory.create(
|
|
128
|
+
provider="redis",
|
|
129
|
+
host="localhost",
|
|
130
|
+
port=6379,
|
|
131
|
+
)
|
|
132
|
+
await queue.connect()
|
|
133
|
+
|
|
134
|
+
message = VsMessage(
|
|
135
|
+
headers={"type": "orchestrator.task", "trace_id": "abc123"},
|
|
136
|
+
payload={"node_id": "xyz", "user_message": "hello"},
|
|
137
|
+
)
|
|
138
|
+
await queue.publish("orchestrator:tasks", message)
|
|
139
|
+
await queue.disconnect()
|
|
140
|
+
|
|
141
|
+
asyncio.run(main())
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Consumer (manual)
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from vs_queue.base.vs_base_consumer import VsBaseConsumer
|
|
148
|
+
from vs_queue.schema.vs_message import VsMessage
|
|
149
|
+
|
|
150
|
+
class OrchestratorConsumer(VsBaseConsumer):
|
|
151
|
+
|
|
152
|
+
async def handle(self, message: VsMessage) -> None:
|
|
153
|
+
node_id = message.payload["node_id"]
|
|
154
|
+
print(f"Processing node: {node_id}")
|
|
155
|
+
|
|
156
|
+
async def start(self) -> None:
|
|
157
|
+
print("OrchestratorConsumer started")
|
|
158
|
+
|
|
159
|
+
async def stop(self) -> None:
|
|
160
|
+
print("OrchestratorConsumer stopped")
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Consumer (annotation-based)
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from vs_queue.decorator.vs_queue_listener import queue_listener
|
|
167
|
+
from vs_queue.base.vs_base_consumer import VsBaseConsumer
|
|
168
|
+
from vs_queue.schema.vs_message import VsMessage
|
|
169
|
+
|
|
170
|
+
@queue_listener(
|
|
171
|
+
queue="orchestrator:tasks",
|
|
172
|
+
concurrency=2,
|
|
173
|
+
max_retries=3,
|
|
174
|
+
retry_backoff_seconds=2.0,
|
|
175
|
+
dead_letter_queue="orchestrator:dlq",
|
|
176
|
+
)
|
|
177
|
+
class OrchestratorConsumer(VsBaseConsumer):
|
|
178
|
+
|
|
179
|
+
async def handle(self, message: VsMessage) -> None:
|
|
180
|
+
node_id = message.payload["node_id"]
|
|
181
|
+
# process the message
|
|
182
|
+
print(f"Processing node: {node_id}")
|
|
183
|
+
|
|
184
|
+
async def start(self) -> None:
|
|
185
|
+
pass
|
|
186
|
+
|
|
187
|
+
async def stop(self) -> None:
|
|
188
|
+
pass
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Starting all listeners
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
from vs_queue.factory.vs_queue_factory import VsQueueFactory
|
|
195
|
+
from vs_queue.manager.vs_queue_manager import VsQueueManager
|
|
196
|
+
|
|
197
|
+
import my_app.consumers # noqa — import modules that contain @queue_listener classes
|
|
198
|
+
|
|
199
|
+
queue = VsQueueFactory.create(provider="redis", host="localhost", port=6379)
|
|
200
|
+
manager = VsQueueManager(queue)
|
|
201
|
+
await manager.register_listeners() # discovers all @queue_listener classes, connects & starts immediately
|
|
202
|
+
|
|
203
|
+
# ... app runs ...
|
|
204
|
+
await manager.stop_all()
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Configuration
|
|
210
|
+
|
|
211
|
+
### Redis
|
|
212
|
+
|
|
213
|
+
```ini
|
|
214
|
+
[queue]
|
|
215
|
+
provider = redis
|
|
216
|
+
host = localhost
|
|
217
|
+
port = 6379
|
|
218
|
+
password = your_redis_password
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### RabbitMQ
|
|
222
|
+
|
|
223
|
+
```ini
|
|
224
|
+
[queue]
|
|
225
|
+
provider = rabbitmq
|
|
226
|
+
host = localhost
|
|
227
|
+
port = 5672
|
|
228
|
+
username = guest
|
|
229
|
+
password = guest
|
|
230
|
+
vhost = /
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## VsMessage
|
|
236
|
+
|
|
237
|
+
Every message published and consumed by `vs-queue` is a `VsMessage`. It is backend-agnostic — the same schema works for Redis Streams and RabbitMQ.
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from vs_queue.schema.vs_message import VsMessage
|
|
241
|
+
|
|
242
|
+
message = VsMessage(
|
|
243
|
+
headers={"type": "orchestrator.task", "trace_id": "abc123", "source_queue": "orchestrator:tasks"},
|
|
244
|
+
payload={"node_id": "xyz", "user_id": "u1"},
|
|
245
|
+
)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**Fields:**
|
|
249
|
+
|
|
250
|
+
| Field | Type | Default | Description |
|
|
251
|
+
|---|---|---|---|
|
|
252
|
+
| `id` | `str` | `uuid4().hex` | Unique message ID, auto-generated |
|
|
253
|
+
| `timestamp` | `datetime` | `now(UTC)` | Message creation time, auto-set |
|
|
254
|
+
| `retry_count` | `int` | `0` | Number of processing attempts. Managed by the library — do not set manually. |
|
|
255
|
+
| `headers` | `Dict[str, str]` | `{}` | Caller-defined metadata: type, trace_id, routing info, etc. |
|
|
256
|
+
| `payload` | `Dict[str, Any]` | `None` | Message body. Structure is defined by the caller. |
|
|
257
|
+
|
|
258
|
+
**Notes:**
|
|
259
|
+
- `id` and `timestamp` are auto-generated — you rarely need to set them.
|
|
260
|
+
- `retry_count` is managed by the retry policy. Do not set it manually.
|
|
261
|
+
- `headers` is a flat `Dict[str, str]`. Nest complex metadata in `payload`.
|
|
262
|
+
- Include `"source_queue"` in headers if you use retry — the retry policy uses it to re-publish.
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
message = VsMessage(
|
|
266
|
+
headers={
|
|
267
|
+
"type": "task.process",
|
|
268
|
+
"trace_id": "abc123",
|
|
269
|
+
"source_queue": "orchestrator:tasks",
|
|
270
|
+
},
|
|
271
|
+
payload={
|
|
272
|
+
"node_id": "n1",
|
|
273
|
+
"conversation_id": "c1",
|
|
274
|
+
"user_message": "what is the weather today?",
|
|
275
|
+
},
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
print(message.id) # e.g. "3f2a1b4c..."
|
|
279
|
+
print(message.timestamp) # e.g. 2026-08-03T10:00:00+00:00
|
|
280
|
+
print(message.retry_count) # 0
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## VsBaseQueue
|
|
286
|
+
|
|
287
|
+
Abstract base class for all queue backends. Extend this to implement a custom provider.
|
|
288
|
+
|
|
289
|
+
**Constructor parameters:**
|
|
290
|
+
|
|
291
|
+
| Parameter | Type | Required | Description |
|
|
292
|
+
|---|---|---|---|
|
|
293
|
+
| `host` | `str` | Yes | Broker host |
|
|
294
|
+
| `port` | `int` | Yes | Broker port |
|
|
295
|
+
| `credentials` | `Dict[str, Any]` | No | Auth credentials. Keys depend on the backend. |
|
|
296
|
+
|
|
297
|
+
**Abstract methods:**
|
|
298
|
+
|
|
299
|
+
| Method | Description |
|
|
300
|
+
|---|---|
|
|
301
|
+
| `connect()` | Establish connection to the broker |
|
|
302
|
+
| `disconnect()` | Close connection cleanly |
|
|
303
|
+
| `health_check()` | Returns `True` if the broker is reachable |
|
|
304
|
+
| `publish(queue, message)` | Publish a `VsMessage` to a named queue |
|
|
305
|
+
| `subscribe(queue, consumer, retry_policy)` | Begin consuming from a queue using a `VsBaseConsumer` |
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## VsBaseConsumer
|
|
310
|
+
|
|
311
|
+
Abstract base class for all consumers. Extend this and implement `handle` to process messages.
|
|
312
|
+
|
|
313
|
+
**Abstract methods:**
|
|
314
|
+
|
|
315
|
+
| Method | Description |
|
|
316
|
+
|---|---|
|
|
317
|
+
| `handle(message)` | Called for every message received. Raise any exception to trigger retry. |
|
|
318
|
+
| `start()` | Called once when the consumer begins. Use for setup. |
|
|
319
|
+
| `stop()` | Called once on graceful shutdown. Use for cleanup. |
|
|
320
|
+
|
|
321
|
+
**Optional override:**
|
|
322
|
+
|
|
323
|
+
| Method | Description |
|
|
324
|
+
|---|---|
|
|
325
|
+
| `on_error(message, error)` | Called when `handle` raises an exception, before retry logic runs. Use for logging or alerting. |
|
|
326
|
+
|
|
327
|
+
**Example with error hook:**
|
|
328
|
+
|
|
329
|
+
```python
|
|
330
|
+
from vs_queue.base.vs_base_consumer import VsBaseConsumer
|
|
331
|
+
from vs_queue.schema.vs_message import VsMessage
|
|
332
|
+
import logging
|
|
333
|
+
|
|
334
|
+
_logger = logging.getLogger(__name__)
|
|
335
|
+
|
|
336
|
+
class TaskConsumer(VsBaseConsumer):
|
|
337
|
+
|
|
338
|
+
async def handle(self, message: VsMessage) -> None:
|
|
339
|
+
result = await process(message.payload)
|
|
340
|
+
if not result:
|
|
341
|
+
raise ValueError(f"Processing failed for node {message.payload['node_id']}")
|
|
342
|
+
|
|
343
|
+
async def start(self) -> None:
|
|
344
|
+
_logger.info("TaskConsumer starting")
|
|
345
|
+
|
|
346
|
+
async def stop(self) -> None:
|
|
347
|
+
_logger.info("TaskConsumer stopping")
|
|
348
|
+
|
|
349
|
+
async def on_error(self, message: VsMessage, error: Exception) -> None:
|
|
350
|
+
_logger.error(f"Message failed | id={message.id} error={error}")
|
|
351
|
+
# send alert, update DB status, etc.
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## @queue_listener
|
|
357
|
+
|
|
358
|
+
Decorator that registers a `VsBaseConsumer` subclass as a listener. `VsQueueManager.register_listeners()` discovers all decorated classes and starts them automatically.
|
|
359
|
+
|
|
360
|
+
**Parameters:**
|
|
361
|
+
|
|
362
|
+
| Parameter | Type | Required | Default | Description |
|
|
363
|
+
|---|---|---|---|---|
|
|
364
|
+
| `queue` | `str` | Yes | — | Queue name to consume from |
|
|
365
|
+
| `concurrency` | `int` | No | `1` | Number of parallel consumer instances to start |
|
|
366
|
+
| `max_retries` | `int` | No | `3` | Max retry attempts before sending to DLQ |
|
|
367
|
+
| `retry_backoff_seconds` | `float` | No | `1.0` | Base delay for exponential backoff between retries |
|
|
368
|
+
| `dead_letter_queue` | `str` | No | `None` | Queue name for messages that exceed max retries |
|
|
369
|
+
|
|
370
|
+
**Example — minimal:**
|
|
371
|
+
|
|
372
|
+
```python
|
|
373
|
+
@queue_listener(queue="tasks")
|
|
374
|
+
class SimpleConsumer(VsBaseConsumer):
|
|
375
|
+
async def handle(self, message: VsMessage) -> None:
|
|
376
|
+
print(message.payload)
|
|
377
|
+
|
|
378
|
+
async def start(self) -> None: pass
|
|
379
|
+
async def stop(self) -> None: pass
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**Example — full configuration:**
|
|
383
|
+
|
|
384
|
+
```python
|
|
385
|
+
@queue_listener(
|
|
386
|
+
queue="orchestrator:tasks",
|
|
387
|
+
concurrency=3,
|
|
388
|
+
max_retries=5,
|
|
389
|
+
retry_backoff_seconds=2.0,
|
|
390
|
+
dead_letter_queue="orchestrator:dlq",
|
|
391
|
+
)
|
|
392
|
+
class OrchestratorConsumer(VsBaseConsumer):
|
|
393
|
+
|
|
394
|
+
async def handle(self, message: VsMessage) -> None:
|
|
395
|
+
trace_id = message.headers.get("trace_id")
|
|
396
|
+
node_id = message.payload["node_id"]
|
|
397
|
+
await run_graph(trace_id, node_id)
|
|
398
|
+
|
|
399
|
+
async def start(self) -> None:
|
|
400
|
+
await db.connect()
|
|
401
|
+
|
|
402
|
+
async def stop(self) -> None:
|
|
403
|
+
await db.disconnect()
|
|
404
|
+
|
|
405
|
+
async def on_error(self, message: VsMessage, error: Exception) -> None:
|
|
406
|
+
await notify_ops(f"Failed: {message.id} — {error}")
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
**Important:** The module containing `@queue_listener` classes must be imported before calling `register_listeners()`, otherwise the decorator never runs and the class is never registered. `register_listeners()` is async and safe to call only once.
|
|
410
|
+
|
|
411
|
+
```python
|
|
412
|
+
import my_app.consumers # noqa — triggers @queue_listener registration
|
|
413
|
+
await manager.register_listeners()
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
## VsQueueManager
|
|
419
|
+
|
|
420
|
+
Manages the lifecycle of all consumers. Connects to the broker, starts consumer tasks, handles graceful shutdown.
|
|
421
|
+
|
|
422
|
+
**Constructor:**
|
|
423
|
+
|
|
424
|
+
| Parameter | Type | Required | Default | Description |
|
|
425
|
+
|---|---|---|---|---|
|
|
426
|
+
| `queue` | `VsBaseQueue` | Yes | — | The queue instance |
|
|
427
|
+
| `max_consumer_restarts` | `int` | No | `3` | Max times a crashed consumer task is restarted before giving up |
|
|
428
|
+
|
|
429
|
+
**Methods:**
|
|
430
|
+
|
|
431
|
+
| Method | Description |
|
|
432
|
+
|---|---|
|
|
433
|
+
| `register(queue_name, consumer)` | Register a consumer, auto-connect if needed, start immediately. Returns a UUID. |
|
|
434
|
+
| `register_listeners()` | Auto-discover all `@queue_listener` classes and register them. Safe to call only once. |
|
|
435
|
+
| `get_listeners()` | Returns `Dict[str, List[VsBaseConsumer]]` — queue name → running consumer instances |
|
|
436
|
+
| `stop_listener(queue_name, uuid=None)` | Stop all consumers on a queue, or one specific consumer by UUID |
|
|
437
|
+
| `stop_all()` | Stop all consumers and disconnect from broker |
|
|
438
|
+
| `health_check()` | Returns `True` if connected and broker is healthy. Returns `False` if not yet connected. |
|
|
439
|
+
|
|
440
|
+
**Example — with vs-server lifecycle:**
|
|
441
|
+
|
|
442
|
+
```python
|
|
443
|
+
from vs_queue.factory.vs_queue_factory import VsQueueFactory
|
|
444
|
+
from vs_queue.manager.vs_queue_manager import VsQueueManager
|
|
445
|
+
from vs_server.lifecycle.vs_lifecycle import startup, shutdown
|
|
446
|
+
import app.consumers # noqa
|
|
447
|
+
|
|
448
|
+
queue = VsQueueFactory.create(provider="redis", host="localhost", port=6379)
|
|
449
|
+
manager = VsQueueManager(queue, max_consumer_restarts=5)
|
|
450
|
+
|
|
451
|
+
@startup
|
|
452
|
+
async def start_consumers():
|
|
453
|
+
await manager.register_listeners()
|
|
454
|
+
|
|
455
|
+
@shutdown
|
|
456
|
+
async def stop_consumers():
|
|
457
|
+
await manager.stop_all()
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
**Example — dynamic registration:**
|
|
461
|
+
|
|
462
|
+
```python
|
|
463
|
+
manager = VsQueueManager(queue)
|
|
464
|
+
|
|
465
|
+
# auto-connects on first register(), starts task immediately
|
|
466
|
+
for tenant_id in ["tenant_a", "tenant_b"]:
|
|
467
|
+
uuid = await manager.register(f"tasks:{tenant_id}", TenantConsumer())
|
|
468
|
+
|
|
469
|
+
# stop one specific consumer
|
|
470
|
+
await manager.stop_listener("tasks:tenant_a", uuid)
|
|
471
|
+
|
|
472
|
+
# stop all consumers on a queue
|
|
473
|
+
await manager.stop_listener("tasks:tenant_b")
|
|
474
|
+
|
|
475
|
+
# inspect running consumers
|
|
476
|
+
listeners = manager.get_listeners()
|
|
477
|
+
# {"tasks:tenant_a": [<TenantConsumer uuid=...>]}
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
---
|
|
481
|
+
|
|
482
|
+
## Retry Policy
|
|
483
|
+
|
|
484
|
+
`VsRetryPolicy` defines what happens when `handle()` raises an exception. Pass it to `subscribe()` on the queue directly, or let `@queue_listener` configure it declaratively.
|
|
485
|
+
|
|
486
|
+
**Constructor:**
|
|
487
|
+
|
|
488
|
+
| Parameter | Type | Default | Description |
|
|
489
|
+
|---|---|---|---|
|
|
490
|
+
| `max_retries` | `int` | `3` | Max attempts before giving up |
|
|
491
|
+
| `backoff_seconds` | `float` | `1.0` | Base delay. Doubles on each retry (exponential backoff). |
|
|
492
|
+
| `dead_letter_queue` | `str` | `None` | Queue for messages that exceed max retries |
|
|
493
|
+
|
|
494
|
+
**Retry timing:**
|
|
495
|
+
|
|
496
|
+
| Attempt | Delay |
|
|
497
|
+
|---|---|
|
|
498
|
+
| 1st retry | 1s |
|
|
499
|
+
| 2nd retry | 2s |
|
|
500
|
+
| 3rd retry | 4s |
|
|
501
|
+
| Beyond max | → DLQ |
|
|
502
|
+
|
|
503
|
+
**Example — manual:**
|
|
504
|
+
|
|
505
|
+
```python
|
|
506
|
+
from vs_queue.retry.vs_retry_policy import VsRetryPolicy
|
|
507
|
+
|
|
508
|
+
retry_policy = VsRetryPolicy(
|
|
509
|
+
max_retries=5,
|
|
510
|
+
backoff_seconds=2.0,
|
|
511
|
+
dead_letter_queue="orchestrator:dlq",
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
await queue.subscribe("orchestrator:tasks", consumer, retry_policy=retry_policy)
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
**Important:** Include `"source_queue"` in the message headers so the retry policy knows where to re-publish:
|
|
518
|
+
|
|
519
|
+
```python
|
|
520
|
+
message = VsMessage(
|
|
521
|
+
headers={
|
|
522
|
+
"source_queue": "orchestrator:tasks",
|
|
523
|
+
"trace_id": "abc123",
|
|
524
|
+
},
|
|
525
|
+
payload={"node_id": "n1"},
|
|
526
|
+
)
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
---
|
|
530
|
+
|
|
531
|
+
## Dead Letter Queue
|
|
532
|
+
|
|
533
|
+
Messages that fail after all retry attempts are published to the dead letter queue (DLQ). The DLQ is just another queue — you can attach a consumer to it for inspection, alerting, or manual replay.
|
|
534
|
+
|
|
535
|
+
**Example — DLQ consumer:**
|
|
536
|
+
|
|
537
|
+
```python
|
|
538
|
+
@queue_listener(queue="orchestrator:dlq")
|
|
539
|
+
class DlqConsumer(VsBaseConsumer):
|
|
540
|
+
|
|
541
|
+
async def handle(self, message: VsMessage) -> None:
|
|
542
|
+
await alert_ops(
|
|
543
|
+
f"Message permanently failed | id={message.id} retries={message.retry_count}",
|
|
544
|
+
payload=message.payload,
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
async def start(self) -> None: pass
|
|
548
|
+
async def stop(self) -> None: pass
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
**Example — replaying a DLQ message:**
|
|
552
|
+
|
|
553
|
+
```python
|
|
554
|
+
dlq_message = ... # fetch from DLQ consumer
|
|
555
|
+
|
|
556
|
+
# Reset retry count and re-publish to the original queue
|
|
557
|
+
dlq_message.retry_count = 0
|
|
558
|
+
await queue.publish("orchestrator:tasks", dlq_message)
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
---
|
|
562
|
+
|
|
563
|
+
## Redis Streams Backend
|
|
564
|
+
|
|
565
|
+
`VsRedisQueue` implements the queue using Redis Streams (`XADD` / `XREADGROUP`). Redis Streams provide persistent, ordered, consumer-group-aware message delivery.
|
|
566
|
+
|
|
567
|
+
**How it works:**
|
|
568
|
+
- `publish` → `XADD queue * field value ...`
|
|
569
|
+
- `subscribe` → `XREADGROUP GROUP group consumer STREAMS queue >`
|
|
570
|
+
- On success → `XACK` removes the message from the pending entries list
|
|
571
|
+
- On failure → retry policy runs; if max retries exceeded → DLQ
|
|
572
|
+
|
|
573
|
+
**Credentials:**
|
|
574
|
+
|
|
575
|
+
| Key | Description |
|
|
576
|
+
|---|---|
|
|
577
|
+
| `password` | Redis AUTH password |
|
|
578
|
+
|
|
579
|
+
**Example:**
|
|
580
|
+
|
|
581
|
+
```python
|
|
582
|
+
from vs_queue.provider.vs_redis_queue import VsRedisQueue
|
|
583
|
+
|
|
584
|
+
queue = VsRedisQueue(
|
|
585
|
+
host="localhost",
|
|
586
|
+
port=6379,
|
|
587
|
+
credentials={"password": "secret"},
|
|
588
|
+
)
|
|
589
|
+
await queue.connect()
|
|
590
|
+
|
|
591
|
+
healthy = await queue.health_check() # True if Redis responds to PING
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
**Consumer group naming:**
|
|
595
|
+
- Group name: `{queue}:group`
|
|
596
|
+
- Consumer name: `{queue}:consumer`
|
|
597
|
+
|
|
598
|
+
These are created automatically on first `subscribe()`. If the stream does not exist yet, it is created via `mkstream=True`.
|
|
599
|
+
|
|
600
|
+
---
|
|
601
|
+
|
|
602
|
+
## RabbitMQ Backend
|
|
603
|
+
|
|
604
|
+
`VsRabbitMQQueue` implements the queue using AMQP via `aio-pika`. Messages are published to the default exchange with the queue name as the routing key. Queues are declared as durable — messages survive broker restarts.
|
|
605
|
+
|
|
606
|
+
**Credentials:**
|
|
607
|
+
|
|
608
|
+
| Key | Default | Description |
|
|
609
|
+
|---|---|---|
|
|
610
|
+
| `username` | `guest` | RabbitMQ username |
|
|
611
|
+
| `password` | `guest` | RabbitMQ password |
|
|
612
|
+
| `vhost` | `/` | RabbitMQ virtual host |
|
|
613
|
+
|
|
614
|
+
**Example:**
|
|
615
|
+
|
|
616
|
+
```python
|
|
617
|
+
from vs_queue.provider.vs_rabbitmq_queue import VsRabbitMQQueue
|
|
618
|
+
|
|
619
|
+
queue = VsRabbitMQQueue(
|
|
620
|
+
host="localhost",
|
|
621
|
+
port=5672,
|
|
622
|
+
credentials={"username": "admin", "password": "secret", "vhost": "/prod"},
|
|
623
|
+
)
|
|
624
|
+
await queue.connect()
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
**Acknowledgement behaviour:**
|
|
628
|
+
- On success → `ack()` removes the message
|
|
629
|
+
- On failure with retry → `ack()` the original, re-publish with incremented `retry_count`
|
|
630
|
+
- On failure beyond max retries → `nack(requeue=False)` + publish to DLQ
|
|
631
|
+
|
|
632
|
+
---
|
|
633
|
+
|
|
634
|
+
## VsQueueRegistry
|
|
635
|
+
|
|
636
|
+
Stores registered queue provider classes by name. Pre-registered providers: `redis`, `rabbitmq`.
|
|
637
|
+
|
|
638
|
+
**Methods:**
|
|
639
|
+
|
|
640
|
+
| Method | Description |
|
|
641
|
+
|---|---|
|
|
642
|
+
| `register(name, queue_class)` | Register a `VsBaseQueue` subclass under a name |
|
|
643
|
+
| `get(name)` | Return the class for a given name. Raises `KeyError` if not found. |
|
|
644
|
+
| `available()` | Return list of all registered provider names |
|
|
645
|
+
|
|
646
|
+
**Example — registering a custom provider:**
|
|
647
|
+
|
|
648
|
+
```python
|
|
649
|
+
from vs_queue.registry.vs_queue_registry import VsQueueRegistry
|
|
650
|
+
from vs_queue.base.vs_base_queue import VsBaseQueue
|
|
651
|
+
|
|
652
|
+
class VsKafkaQueue(VsBaseQueue):
|
|
653
|
+
async def connect(self): ...
|
|
654
|
+
async def disconnect(self): ...
|
|
655
|
+
async def health_check(self): ...
|
|
656
|
+
async def publish(self, queue, message): ...
|
|
657
|
+
async def subscribe(self, queue, consumer, retry_policy=None): ...
|
|
658
|
+
|
|
659
|
+
VsQueueRegistry.register("kafka", VsKafkaQueue)
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
Once registered, the factory can create it:
|
|
663
|
+
|
|
664
|
+
```python
|
|
665
|
+
queue = VsQueueFactory.create(provider="kafka", host="localhost", port=9092)
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
---
|
|
669
|
+
|
|
670
|
+
## VsQueueFactory
|
|
671
|
+
|
|
672
|
+
Creates queue instances from a registered provider name.
|
|
673
|
+
|
|
674
|
+
**Methods:**
|
|
675
|
+
|
|
676
|
+
| Method | Signature | Description |
|
|
677
|
+
|---|---|---|
|
|
678
|
+
| `create` | `create(provider, host, port, credentials) -> VsBaseQueue` | Create and return a queue instance. Does not call `connect()`. |
|
|
679
|
+
|
|
680
|
+
**Example:**
|
|
681
|
+
|
|
682
|
+
```python
|
|
683
|
+
from vs_queue.factory.vs_queue_factory import VsQueueFactory
|
|
684
|
+
|
|
685
|
+
queue = VsQueueFactory.create(
|
|
686
|
+
provider="redis",
|
|
687
|
+
host="localhost",
|
|
688
|
+
port=6379,
|
|
689
|
+
credentials={"password": "secret"},
|
|
690
|
+
)
|
|
691
|
+
await queue.connect()
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
---
|
|
695
|
+
|
|
696
|
+
## Extending vs-queue
|
|
697
|
+
|
|
698
|
+
### Custom Queue Provider
|
|
699
|
+
|
|
700
|
+
Implement `VsBaseQueue` and register it:
|
|
701
|
+
|
|
702
|
+
```python
|
|
703
|
+
from vs_queue.base.vs_base_queue import VsBaseQueue
|
|
704
|
+
from vs_queue.base.vs_base_consumer import VsBaseConsumer
|
|
705
|
+
from vs_queue.retry.vs_retry_policy import VsRetryPolicy
|
|
706
|
+
from vs_queue.schema.vs_message import VsMessage
|
|
707
|
+
from vs_queue.registry.vs_queue_registry import VsQueueRegistry
|
|
708
|
+
from typing import Optional
|
|
709
|
+
|
|
710
|
+
class VsSqsQueue(VsBaseQueue):
|
|
711
|
+
|
|
712
|
+
def __init__(self, host: str, port: int, credentials=None):
|
|
713
|
+
super().__init__(host, port, credentials)
|
|
714
|
+
self._client = None
|
|
715
|
+
|
|
716
|
+
async def connect(self) -> None:
|
|
717
|
+
import aiobotocore.session
|
|
718
|
+
session = aiobotocore.session.get_session()
|
|
719
|
+
self._client = await session.create_client(
|
|
720
|
+
"sqs",
|
|
721
|
+
region_name=self._credentials.get("region", "us-east-1"),
|
|
722
|
+
aws_access_key_id=self._credentials.get("access_key"),
|
|
723
|
+
aws_secret_access_key=self._credentials.get("secret_key"),
|
|
724
|
+
).__aenter__()
|
|
725
|
+
|
|
726
|
+
async def disconnect(self) -> None:
|
|
727
|
+
if self._client:
|
|
728
|
+
await self._client.__aexit__(None, None, None)
|
|
729
|
+
|
|
730
|
+
async def health_check(self) -> bool:
|
|
731
|
+
try:
|
|
732
|
+
await self._client.list_queues(MaxResults=1)
|
|
733
|
+
return True
|
|
734
|
+
except Exception:
|
|
735
|
+
return False
|
|
736
|
+
|
|
737
|
+
async def publish(self, queue: str, message: VsMessage) -> None:
|
|
738
|
+
import json
|
|
739
|
+
await self._client.send_message(
|
|
740
|
+
QueueUrl=queue,
|
|
741
|
+
MessageBody=json.dumps({"id": message.id, "payload": message.payload, "headers": message.headers}),
|
|
742
|
+
)
|
|
743
|
+
|
|
744
|
+
async def subscribe(self, queue: str, consumer: VsBaseConsumer, retry_policy: Optional[VsRetryPolicy] = None) -> None:
|
|
745
|
+
await consumer.start()
|
|
746
|
+
try:
|
|
747
|
+
while True:
|
|
748
|
+
response = await self._client.receive_message(QueueUrl=queue, WaitTimeSeconds=20)
|
|
749
|
+
for msg in response.get("Messages", []):
|
|
750
|
+
# parse and call consumer.handle(message)
|
|
751
|
+
...
|
|
752
|
+
finally:
|
|
753
|
+
await consumer.stop()
|
|
754
|
+
|
|
755
|
+
VsQueueRegistry.register("sqs", VsSqsQueue)
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
---
|
|
759
|
+
|
|
760
|
+
## Full Example — Orchestrator Integration
|
|
761
|
+
|
|
762
|
+
**Publisher (chat controller):**
|
|
763
|
+
|
|
764
|
+
```python
|
|
765
|
+
from vs_queue.factory.vs_queue_factory import VsQueueFactory
|
|
766
|
+
from vs_queue.schema.vs_message import VsMessage
|
|
767
|
+
|
|
768
|
+
queue = VsQueueFactory.create(provider="redis", host="localhost", port=6379)
|
|
769
|
+
await queue.connect()
|
|
770
|
+
|
|
771
|
+
await queue.publish(
|
|
772
|
+
"orchestrator:tasks",
|
|
773
|
+
VsMessage(
|
|
774
|
+
headers={
|
|
775
|
+
"type": "orchestrator.task",
|
|
776
|
+
"trace_id": trace_id,
|
|
777
|
+
"source_queue": "orchestrator:tasks",
|
|
778
|
+
},
|
|
779
|
+
payload={
|
|
780
|
+
"node_id": node["node"]["id"],
|
|
781
|
+
"conversation_id": node["conversation_id"],
|
|
782
|
+
"user_message": request.message,
|
|
783
|
+
"user_id": user_id,
|
|
784
|
+
},
|
|
785
|
+
),
|
|
786
|
+
)
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
**Consumer (orchestrator worker):**
|
|
790
|
+
|
|
791
|
+
```python
|
|
792
|
+
from vs_queue.decorator.vs_queue_listener import queue_listener
|
|
793
|
+
from vs_queue.base.vs_base_consumer import VsBaseConsumer
|
|
794
|
+
from vs_queue.schema.vs_message import VsMessage
|
|
795
|
+
from orchestrator_agent.graph.orchestrator_graph import OrchestratorGraph
|
|
796
|
+
from orchestrator_agent.graph.orchestrator_state import OrchestratorState
|
|
797
|
+
|
|
798
|
+
@queue_listener(
|
|
799
|
+
queue="orchestrator:tasks",
|
|
800
|
+
concurrency=2,
|
|
801
|
+
max_retries=3,
|
|
802
|
+
retry_backoff_seconds=2.0,
|
|
803
|
+
dead_letter_queue="orchestrator:dlq",
|
|
804
|
+
)
|
|
805
|
+
class OrchestratorTaskConsumer(VsBaseConsumer):
|
|
806
|
+
|
|
807
|
+
def __init__(self):
|
|
808
|
+
super().__init__()
|
|
809
|
+
self._graph = OrchestratorGraph()
|
|
810
|
+
|
|
811
|
+
async def handle(self, message: VsMessage) -> None:
|
|
812
|
+
payload = message.payload
|
|
813
|
+
result = await self._graph.invoke(OrchestratorState(
|
|
814
|
+
trace_id=message.headers.get("trace_id", ""),
|
|
815
|
+
error=None,
|
|
816
|
+
current_message=payload["user_message"],
|
|
817
|
+
user_id=payload["user_id"],
|
|
818
|
+
message=payload["user_message"],
|
|
819
|
+
resolved_context=None,
|
|
820
|
+
response=None,
|
|
821
|
+
))
|
|
822
|
+
|
|
823
|
+
async def start(self) -> None:
|
|
824
|
+
pass
|
|
825
|
+
|
|
826
|
+
async def stop(self) -> None:
|
|
827
|
+
pass
|
|
828
|
+
|
|
829
|
+
async def on_error(self, message: VsMessage, error: Exception) -> None:
|
|
830
|
+
import logging
|
|
831
|
+
logging.getLogger(__name__).error(
|
|
832
|
+
f"Graph execution failed | node_id={message.payload.get('node_id')} error={error}"
|
|
833
|
+
)
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
**App startup:**
|
|
837
|
+
|
|
838
|
+
```python
|
|
839
|
+
from vs_queue.factory.vs_queue_factory import VsQueueFactory
|
|
840
|
+
from vs_queue.manager.vs_queue_manager import VsQueueManager
|
|
841
|
+
from vs_server.lifecycle.vs_lifecycle import startup, shutdown
|
|
842
|
+
import orchestrator_agent.consumers # noqa — registers @queue_listener classes
|
|
843
|
+
|
|
844
|
+
queue = VsQueueFactory.create(provider="redis", host="localhost", port=6379)
|
|
845
|
+
manager = VsQueueManager(queue, max_consumer_restarts=5)
|
|
846
|
+
|
|
847
|
+
@startup
|
|
848
|
+
async def start_consumers():
|
|
849
|
+
await manager.register_listeners()
|
|
850
|
+
|
|
851
|
+
@shutdown
|
|
852
|
+
async def stop_consumers():
|
|
853
|
+
await manager.stop_all()
|
|
854
|
+
```
|
|
855
|
+
|
|
856
|
+
---
|
|
857
|
+
|
|
858
|
+
## Class Reference
|
|
859
|
+
|
|
860
|
+
---
|
|
861
|
+
|
|
862
|
+
### VsMessage
|
|
863
|
+
|
|
864
|
+
Standard message envelope. Every message published and consumed by `vs-queue` is a `VsMessage`.
|
|
865
|
+
|
|
866
|
+
| Field | Type | Default | Description |
|
|
867
|
+
|---|---|---|---|
|
|
868
|
+
| `id` | `str` | `uuid4().hex` | Auto-generated unique ID |
|
|
869
|
+
| `timestamp` | `datetime` | `now(UTC)` | Auto-set creation time |
|
|
870
|
+
| `retry_count` | `int` | `0` | Managed by retry policy |
|
|
871
|
+
| `headers` | `Dict[str, str]` | `{}` | Caller metadata |
|
|
872
|
+
| `payload` | `Dict[str, Any]` | `None` | Message body |
|
|
873
|
+
|
|
874
|
+
---
|
|
875
|
+
|
|
876
|
+
### VsBaseQueue
|
|
877
|
+
|
|
878
|
+
Abstract base. Extend to implement a custom queue provider.
|
|
879
|
+
|
|
880
|
+
| Method | Description |
|
|
881
|
+
|---|---|
|
|
882
|
+
| `connect()` | Establish broker connection |
|
|
883
|
+
| `disconnect()` | Close connection cleanly |
|
|
884
|
+
| `health_check()` | Returns `True` if broker is reachable |
|
|
885
|
+
| `publish(queue, message)` | Publish a message |
|
|
886
|
+
| `subscribe(queue, consumer, retry_policy)` | Start consuming |
|
|
887
|
+
|
|
888
|
+
---
|
|
889
|
+
|
|
890
|
+
### VsBaseConsumer
|
|
891
|
+
|
|
892
|
+
Abstract base. Extend and implement `handle` to process messages.
|
|
893
|
+
|
|
894
|
+
**Attribute:**
|
|
895
|
+
|
|
896
|
+
| Attribute | Type | Description |
|
|
897
|
+
|---|---|---|
|
|
898
|
+
| `uuid` | `Optional[str]` | Set automatically at registration time. Use it with `stop_listener()` to stop a specific instance. |
|
|
899
|
+
|
|
900
|
+
**Methods:**
|
|
901
|
+
|
|
902
|
+
| Method | Required | Description |
|
|
903
|
+
|---|---|---|
|
|
904
|
+
| `handle(message)` | Yes | Process a message. Raise to trigger retry. |
|
|
905
|
+
| `start()` | Yes | Setup before consuming begins |
|
|
906
|
+
| `stop()` | Yes | Cleanup on shutdown — called on graceful cancel |
|
|
907
|
+
| `on_error(message, error)` | No | Called on `handle` failure before retry |
|
|
908
|
+
|
|
909
|
+
---
|
|
910
|
+
|
|
911
|
+
### VsQueueManager
|
|
912
|
+
|
|
913
|
+
Lifecycle manager for all consumers.
|
|
914
|
+
|
|
915
|
+
| Method | Description |
|
|
916
|
+
|---|---|
|
|
917
|
+
| `register(queue_name, consumer)` | Register a consumer, auto-connect, start immediately. Returns UUID. |
|
|
918
|
+
| `register_listeners()` | Auto-discover `@queue_listener` classes. Safe to call only once. |
|
|
919
|
+
| `get_listeners()` | Returns `Dict[str, List[VsBaseConsumer]]` |
|
|
920
|
+
| `stop_listener(queue_name, uuid=None)` | Stop one or all consumers on a queue |
|
|
921
|
+
| `stop_all()` | Stop all consumers and disconnect |
|
|
922
|
+
| `health_check()` | Returns `True` if connected and broker is healthy |
|
|
923
|
+
|
|
924
|
+
---
|
|
925
|
+
|
|
926
|
+
### VsRetryPolicy
|
|
927
|
+
|
|
928
|
+
Defines retry and DLQ behaviour on consumer failure.
|
|
929
|
+
|
|
930
|
+
| Parameter | Default | Description |
|
|
931
|
+
|---|---|---|
|
|
932
|
+
| `max_retries` | `3` | Max attempts |
|
|
933
|
+
| `backoff_seconds` | `1.0` | Base exponential backoff delay |
|
|
934
|
+
| `dead_letter_queue` | `None` | DLQ name |
|
|
935
|
+
|
|
936
|
+
---
|
|
937
|
+
|
|
938
|
+
### VsQueueRegistry
|
|
939
|
+
|
|
940
|
+
Registry of queue provider classes.
|
|
941
|
+
|
|
942
|
+
| Method | Description |
|
|
943
|
+
|---|---|
|
|
944
|
+
| `register(name, queue_class)` | Register a provider |
|
|
945
|
+
| `get(name)` | Get a provider class by name |
|
|
946
|
+
| `available()` | List all registered provider names |
|
|
947
|
+
|
|
948
|
+
---
|
|
949
|
+
|
|
950
|
+
### VsQueueFactory
|
|
951
|
+
|
|
952
|
+
Creates queue instances from the registry.
|
|
953
|
+
|
|
954
|
+
| Method | Description |
|
|
955
|
+
|---|---|
|
|
956
|
+
| `create(provider, host, port, credentials)` | Instantiate a queue. Call `connect()` before use. |
|
|
957
|
+
|
|
958
|
+
---
|
|
959
|
+
|
|
960
|
+
### `@queue_listener`
|
|
961
|
+
|
|
962
|
+
Decorator. Registers a `VsBaseConsumer` subclass for auto-discovery by `VsQueueManager`.
|
|
963
|
+
|
|
964
|
+
| Parameter | Default | Description |
|
|
965
|
+
|---|---|---|
|
|
966
|
+
| `queue` | — | Queue name |
|
|
967
|
+
| `concurrency` | `1` | Parallel consumer instances |
|
|
968
|
+
| `max_retries` | `3` | Max retries on failure |
|
|
969
|
+
| `retry_backoff_seconds` | `1.0` | Exponential backoff base delay |
|
|
970
|
+
| `dead_letter_queue` | `None` | DLQ name |
|
|
971
|
+
|
|
972
|
+
---
|
|
973
|
+
|
|
974
|
+
## Running Tests
|
|
975
|
+
|
|
976
|
+
```bash
|
|
977
|
+
./run_tests.sh
|
|
978
|
+
```
|