feat: implement transactional outbox, dlq and worker timeouts

This commit is contained in:
2026-11-12 21:35:48 +03:00
parent 067b2d866f
commit 479dacc934
7 changed files with 278 additions and 221 deletions
+18 -1
View File
@@ -4,11 +4,28 @@ import json
RABBITMQ_URL = os.getenv("RABBITMQ_URL", "amqp://guest:guest@rabbitmq:5672/")
QUEUE_NAME = "attachment_tasks"
DLQ_NAME = "attachment_tasks_dlq"
def setup_rabbitmq(channel):
# Создаем Dead Letter Exchange и Queue
channel.exchange_declare(exchange='dlx', exchange_type='direct', durable=True)
channel.queue_declare(queue=DLQ_NAME, durable=True)
channel.queue_bind(exchange='dlx', queue=DLQ_NAME, routing_key='dlq')
# Основная очередь, привязанная к DLX
channel.queue_declare(
queue=QUEUE_NAME,
durable=True,
arguments={
'x-dead-letter-exchange': 'dlx',
'x-dead-letter-routing-key': 'dlq'
}
)
def publish_task(task: dict):
connection = pika.BlockingConnection(pika.URLParameters(RABBITMQ_URL))
channel = connection.channel()
channel.queue_declare(queue=QUEUE_NAME, durable=True)
setup_rabbitmq(channel)
channel.basic_publish(
exchange="",
routing_key=QUEUE_NAME,