fix(queue-amqp): prevent infinite poison-pill loop on message error by supporting requeue: false and DLQ routing #20
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
qa:preview
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
quatrain/core#20
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
🎯 Goal
Prevent infinite redelivery loops ("poison pill") in
@quatrain/queue-amqpby enabling configurable negative acknowledgment (requeue: false) and proper Dead Letter Queue (DLQ) routing when a message handler fails.📋 Context & Problem Statement
In
packages/queue-amqp/src/AmqpQueueAdapter.ts(lines 129–138):requeue: trueinamqplib:The method signature is
channel.nack(message, allUpTo?, requeue?). Omittingrequeuedefaults totrue.The inline comment states "Negative acknowledge the message so it can be requeued or handled by DLQ". However, RabbitMQ never dead-letters a message when
requeue: true; it only routes messages to a Dead Letter Exchange (DLX) when negatively acknowledged withrequeue: false(or when TTL/length limits expire).Calling
channel.nack(msg)withrequeue: truefollowed byprocess.exit(1)causes RabbitMQ to put the failed message back at the head of the queue immediately. When the container restarts in Kubernetes or another worker replica consumes the queue, the exact same deterministically broken message is picked up again, causing infinite CrashLoopBackOff and cluster resource exhaustion.🛠️ Proposed Solution & Architecture
Add a
requeueOnErrorparameter inQueueListenOptions/AmqpQueueAdapter:channel.nack(msg, false, requeue):Update
AmqpQueueAdapter.ts: Whenrequeueisfalse, RabbitMQ will either drop the poison message or route it to the configured Dead Letter Exchange (DLX/DLQ) if dead-lettering is enabled on the queue (x-dead-letter-exchange).Rather than unconditionally executing
process.exit(1)for every message failure, allow configuring whether the worker process should terminate on handler error or continue processing subsequent messages once the failed message has been safely dead-lettered / nacked.🧪 Acceptance Criteria
channel.nackinAmqpQueueAdapterrespects a configurablerequeueflag (requeue: falsesupported).listen()behavior on message handler failure with bothrequeue: falseandrequeue: true.