Add dead-letter queue for rejected broker messages

This commit is contained in:
Polusikkkk
2026-12-04 16:31:03 +03:00
parent be223efc8b
commit f4e79cb937
2 changed files with 19 additions and 0 deletions
+17
View File
@@ -7,6 +7,8 @@ import pika
QUEUE_NAME = "attachment.process.v1"
DLX_NAME = "attachment.process.dlx"
DLQ_NAME = "attachment.process.v1.dlq"
def connect_broker():
@@ -24,11 +26,26 @@ def connect_broker():
connection = pika.BlockingConnection(parameters)
try:
channel = connection.channel()
channel.exchange_declare(
exchange=DLX_NAME,
exchange_type="direct",
durable=True,
)
channel.queue_declare(queue=DLQ_NAME, durable=True)
channel.queue_bind(
queue=DLQ_NAME,
exchange=DLX_NAME,
routing_key=QUEUE_NAME,
)
channel.queue_declare(
queue=QUEUE_NAME,
durable=True,
exclusive=False,
auto_delete=False,
arguments={
"x-dead-letter-exchange": DLX_NAME,
"x-dead-letter-routing-key": QUEUE_NAME,
},
)
return connection, channel
except Exception: