TASK
Implementation
Implement dead letter queues for failed messages:
- Track retry count for each message
- On processing failure, increment retry count
- After N failures, move to dead letter queue
- Preserve: original message, error details, timestamps
- Provide interface to inspect and replay DLQ messages
DLQs prevent poison messages from blocking the queue.
Sample Test Cases
Move to DLQ after retriesTimeout: 5000ms
Input
{
"src": "c0",
"dest": "n1",
"body": {
"type": "init",
"msg_id": 1,
"node_id": "n1",
"node_ids": [
"n1"
]
}
}Expected Output
{"src":"n1","dest":"c0","body":{"type":"init_ok","in_reply_to":1,"msg_id":0}}Replay from DLQTimeout: 5000ms
Input
{
"src": "c0",
"dest": "n1",
"body": {
"type": "init",
"msg_id": 1,
"node_id": "n1",
"node_ids": [
"n1"
]
}
}Expected Output
{"src":"n1","dest":"c0","body":{"type":"init_ok","in_reply_to":1,"msg_id":0}}Hints
Hint 1▾
Track retry count per message
Hint 2▾
Move to DLQ after max retries
Hint 3▾
Preserve error information
OVERVIEW
Theoretical Hub
Dead Letter Queues
Some messages may never succeed: invalid format, missing data, bugs. Instead of retrying forever or losing them, move failures to a DLQ for investigation. Operators can fix issues and replay messages.
Poison Messages
A poison message is one that consistently fails processing. Without DLQ, it blocks the queue (if ordered) or wastes resources (if retried forever). DLQ isolates the poison so healthy messages flow.
Key Concepts
DLQpoison messageerror handling
main.py
python
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
#!/usr/bin/env python3
import sys
import json
import time
import uuid
class DLQQueue:
def __init__(self, max_retries=3):
self.main_queue = []
self.dlq = []
self.retry_counts = {} # message_id -> count
self.max_retries = max_retries
def send(self, message):
# TODO: Add to main queue with ID
pass
def receive(self):
# TODO: Get next message
pass
def nack(self, message_id, error):
# TODO: Increment retry, move to DLQ if max
pass
def ack(self, message_id):
# TODO: Remove from queue, clear retry count
pass
def get_dlq_messages(self):
# TODO: Return all DLQ messages with metadata
pass
def replay_from_dlq(self, message_id):
# TODO: Move message back to main queue
pass
if __name__ == "__main__":
pass