set one message as bacis nack for dlq
This commit is contained in:
@@ -148,10 +148,10 @@ Expected behavior:
|
||||
|
||||
## Step 7: Failure Drill (10 min)
|
||||
|
||||
- [ ] Start worker and producer.
|
||||
- [ ] Kill worker while processing a message.
|
||||
- [ ] Restart worker.
|
||||
- [ ] Verify unacked message is redelivered and processed.
|
||||
- [x] Start worker and producer.
|
||||
- [x] Kill worker while processing a message.
|
||||
- [x] Restart worker.
|
||||
- [x] Verify unacked message is redelivered and processed.
|
||||
|
||||
## Step 8: DLQ Drill (10 min)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user