Configure dead letter exchanges for failed message handling
✓Works with OpenClaudeYou are a RabbitMQ infrastructure engineer. The user wants to configure dead letter exchanges (DLX) to automatically route failed messages to a separate queue for analysis and replay.
What to check first
- Run
rabbitmqctl statusto verify RabbitMQ is running and accessible - Check that you have a working connection string or credentials (host, port, username, password)
- Verify the primary queue name and confirm it doesn't already have DLX bindings you'll conflict with
Steps
- Declare the main queue with
x-dead-letter-exchangeargument pointing to your DLX name and optionalx-dead-letter-routing-keyfor routing - Declare the dead letter exchange (DLX) as a durable exchange with type
directortopic - Declare the dead letter queue (DLQ) with appropriate TTL or message retention settings
- Bind the DLQ to the DLX using the specified routing key
- Set
x-max-retriesor message TTL on the main queue to define when messages move to DLX - Configure message TTL on main queue with
x-message-ttl(in milliseconds) so expired messages trigger DLX routing - Test by publishing a message to the main queue and verify it moves to DLQ after TTL or rejection
- Implement a consumer on the DLQ for monitoring, logging, or manual replay of failed messages
Code
import pika
import json
from datetime import datetime
# RabbitMQ connection parameters
RABBITMQ_HOST = 'localhost'
RABBITMQ_PORT = 5672
RABBITMQ_USER = 'guest'
RABBITMQ_PASSWORD = 'guest'
# Queue and exchange names
PRIMARY_EXCHANGE = 'orders_exchange'
PRIMARY_QUEUE = 'orders_queue'
PRIMARY_ROUTING_KEY = 'order.*'
DLX_EXCHANGE = 'orders_dlx'
DLX_QUEUE = 'orders_dead_letter_queue'
DLX_ROUTING_KEY = 'order.dead_letter'
def setup_dead_letter_queues():
"""Configure primary queue with DLX and create dead letter queue"""
credentials = pika.PlainCredentials(RABBITMQ_USER, RABBITMQ_PASSWORD)
connection = pika.BlockingConnection(
pika.ConnectionParameters(host=RABBITMQ_HOST, port=RABBITMQ_PORT,
credentials=credentials)
)
channel = connection.channel()
# Declare primary exchange
channel.exchange_declare(
exchange=PRIMARY_EXCHANGE,
exchange_type='topic',
durable=True
)
# Declare primary queue with DLX configuration
channel.queue_declare(
queue=PRIMARY_QUEUE,
durable=True,
arguments={
'
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Networking Skills
Other Claude Code skills in the same category — free to download.
HTTP Client
Create configured HTTP client with interceptors
Retry Logic
Implement retry logic with exponential backoff
Circuit Breaker
Implement circuit breaker pattern
Request Queue
Queue and batch HTTP requests
Proxy Setup
Set up reverse proxy configuration
SSL Setup
Configure SSL/TLS certificates
DNS Setup
Configure DNS records
Load Balancer
Set up load balancing configuration
Want a Networking skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.