Skip to content

Requeue a delivery the handler refused and stop consuming - #143

Merged
KalimeroMK merged 2 commits into
masterfrom
fix-346-requeue-refused-delivery
Oct 29, 2026
Merged

KalimeroMK merged 2 commits into
masterfrom
fix-346-requeue-refused-delivery

Conversation

@samdark

@samdark samdark commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Related to yiisoft/queue#346. It should be merged together with yiisoft/queue#349.

It builds on #144, which makes the package work with the current yiisoft/queue, and includes its commit. Merge #144 first.

Adapter::subscribe() acknowledged every delivery after calling the handler, whatever the handler returned. With yiisoft/queue#349, QueueConsumer returns false for a message it did not process because the loop has stopped. Such a delivery, for example one that arrives during wait() after SIGTERM or a prefetched one, would be acknowledged without being processed, and so lost.

Now subscribe() handles the handler result:

  • true: the delivery is acknowledged, as before.
  • false: the delivery is nacked with requeue, the consumer is cancelled and the wait loop stops.
  • Deliveries that arrive after that are requeued without calling the handler.
  • An exception from the handler still cancels the consumer and is rethrown, without an acknowledgement.

runExisting() already requeued a refused message and is unchanged.

The two changes have to land together. Without this one, yiisoft/queue#349 lets unprocessed AMQP deliveries be acknowledged. Without yiisoft/queue#349, the current QueueConsumer returns false after processing a message when the loop stops, so that message would be requeued and processed twice.

yiisoft/queue#321 removed Provider\QueueProviderInterface and Queue. The queue settings used
QueueProviderInterface::DEFAULT_QUEUE as the default queue name, so the package could not be loaded with the
current yiisoft/queue. It now uses DefaultQueue::NAME, which has the same value.

The tests and the test console application now use AsyncQueueProducer and QueueConsumer instead of Queue, and
build the worker with the current Worker constructor.
subscribe() acknowledged every delivery regardless of the handler result. The queue consumer
returns false for a message it did not process (the loop was stopped), so such a message was
acknowledged and lost. Now false nacks the delivery with requeue, cancels the consumer and stops
the wait loop; deliveries that arrive after that are requeued without calling the handler.

@KalimeroMK KalimeroMK left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matches what runExisting() already does, and the three paths are covered. Two notes inline, neither blocking.

Comment thread src/Adapter.php Resolved
Comment thread src/Adapter.php Resolved
@KalimeroMK
KalimeroMK merged commit 1fc9e30 into master Oct 29, 2026
21 checks passed
@KalimeroMK
KalimeroMK deleted the fix-346-requeue-refused-delivery branch October 29, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants