Repository navigation
Subscribe the queues again after a reconnect - #97
Merged
Merged
Conversation
A reconnect opens a new consume channel, but the queues kept the old one and their consumers died with it. Apps that don't create their queues again on 'connected' kept running with no consumers and reported healthy. openConnections now rebinds every queue to the new channel before emitting 'connected': declares it again, adds its exchange bindings again and subscribes its handler with the queue's own prefetch. A queue that fails to subscribe is retried by the resubscribe loop. createQueue with a handler cancels an existing consumer on the same channel, so apps that do create their queues again on 'connected' don't end up with two consumers. Co-Authored-By: Claude <noreply@anthropic.com>
…esubscribe On by default. With false, a reconnect leaves the queues alone and the app creates them again on 'connected', as before. Co-Authored-By: Claude <noreply@anthropic.com>
nikosd23
force-pushed
the
fix/resubscribe-queues-after-reconnect
branch
from
November 11, 2026 07:52
4f7bbf3 to
6303b58
Compare
ikarachristos
approved these changes
Nov 11, 2026
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After a reconnect, rabbit-queue opens a new consume channel but the queues keep the old one, and their consumers die with it. Nothing subscribes them again unless the app creates its queues on
connected. An app that doesn't (for example one built on a wrapper that only logsconnected) reconnects, reports healthy, and has 0 consumers until it is restarted.To reproduce: subscribe a queue, run
rabbitmqctl close_all_connections, wait forconnected, then runrabbitmqctl list_consumers. The queue has no consumer, and a published message is never handled.Change
openConnectionsnow rebinds every queue inthis.queuesto the new consume channel before it emitsconnected: declares the queue again, adds its exchange bindings again (now tracked onQueue), and subscribes its handler with the queue's own prefetch. The sameQueueobjects are reused, so references such asBaseQueueHandler.queuestay valid.connectedisn't emitted.createQueuewith a handler cancels an existing consumer for the same queue on the same channel first. Apps that follow the README and create their queues onconnectedreplace the rebound consumer instead of adding a second one.resubscribeOnReconnect(defaulttrue). Withfalse, a reconnect leaves the queues alone, as in 5.12.0.connectedexample, changelog entry (5.13.x).Behaviour change
Subscribing again on reconnect is now the default. The README described it as the app's job before. I kept that pattern safe (no duplicate consumers) and added the opt-out.
Testing
Against a local RabbitMQ 3.13.6: full suite passes (159 tests). 9 new reconnect tests cover both connections or only the consume connection dropping, repeated reconnects ending with 1 consumer, the queue's own prefetch, an unsubscribed queue staying unsubscribed, exclusive-queue bindings, consumers being back when
connectedfires, the retry path, and the opt-out. Without thets/changes, 7 of them fail.Not run:
npm run test-docker(RabbitMQ 4.x).To do after merge