set one message as bacis nack for dlq

This commit is contained in:
2026-04-14 21:57:44 +00:00
parent 7ef72a0446
commit afcef61972
2 changed files with 12 additions and 4 deletions
+8
View File
@@ -46,12 +46,20 @@ def on_message(
_ = properties
order: OrderMessage = json.loads(body)
order_id = order["order_id"]
retry_count = order.get("retry_count", 0)
should_fail = order.get("should_fail", False)
print(f"[worker] got order={order_id} retry={retry_count}")
time.sleep(1)
if order_id == 1003:
print(f"sending 1003 to dlq")
# basic nack by defaul will reque and not be a dead letter
# you need to have requeue=False
channel.basic_nack(delivery_tag=method.delivery_tag, requeue=False)
return
if should_fail and retry_count < 2:
order["retry_count"] = retry_count + 1
publish_status("order.created", order) # this key, this obj