Skip to content

feat(consumer): declarative topology restored on reconnect + fix consume-loop wedge#16

Merged
KARTIKrocks merged 2 commits into
mainfrom
feat/consumer-reconnect-topology
Jul 5, 2026
Merged

feat(consumer): declarative topology restored on reconnect + fix consume-loop wedge#16
KARTIKrocks merged 2 commits into
mainfrom
feat/consumer-reconnect-topology

Conversation

@KARTIKrocks

@KARTIKrocks KARTIKrocks commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Add ConsumerConfig.WithQueueConfig and WithBinding (new BindingConfig type): the consumer re-applies the configured queue and bindings on every channel setup — initially and after each reconnect. Previously a named exclusive/auto-delete queue was deleted by the broker on connection loss and never re-created or re-bound, silently killing the consumer.

Fix the consume loop wedging forever when consuming fails while the connection is healthy (queue deleted / basic.cancel / precondition failure): no reconnect signal ever arrives, so waitForReconnect now also retries setup on a timer.

Also close the previous channel when re-establishing on a healthy connection instead of leaking it, and drop a channel set up concurrently with Close.

Summary

Motivation

Fixes #

Changes

Checklist

  • fmt, vet, lint, test, build passes (make all)
  • New code has tests where appropriate
  • Breaking changes are documented

Summary by CodeRabbit

  • New Features

    • Added declarative consumer topology support so queue and binding setup is restored automatically after reconnects.
    • Added configuration options to define queue settings and message bindings directly in consumer setup.
    • Improved recovery so consumption can continue even if a queue is deleted or a reconnect signal is delayed.
  • Bug Fixes

    • Prevented consumers from getting stuck during reconnect handling.
    • Reduced the risk of channel leaks when replacing or closing consumer connections.
  • Documentation

    • Updated release notes and README with the new topology and reconnect behavior.

…ume-loop wedge

Add ConsumerConfig.WithQueueConfig and WithBinding (new BindingConfig type):
the consumer re-applies the configured queue and bindings on every channel
setup — initially and after each reconnect. Previously a named
exclusive/auto-delete queue was deleted by the broker on connection loss and
never re-created or re-bound, silently killing the consumer.

Fix the consume loop wedging forever when consuming fails while the connection
is healthy (queue deleted / basic.cancel / precondition failure): no reconnect
signal ever arrives, so waitForReconnect now also retries setup on a timer.

Also close the previous channel when re-establishing on a healthy connection
instead of leaking it, and drop a channel set up concurrently with Close.
@KARTIKrocks

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@KARTIKrocks, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e0cae552-9c4b-44ce-bae9-d0f525393da7

📥 Commits

Reviewing files that changed from the base of the PR and between d8e2b72 and a260dea.

📒 Files selected for processing (2)
  • consumer.go
  • integration_test.go

Walkthrough

This PR adds declarative consumer topology to rabbitwrap: ConsumerConfig gains QueueConfig and Bindings fields with WithQueueConfig/WithBinding builders, reapplied via a new applyTopology helper on every channel setup (including reconnects). It also fixes consume-loop stalling and prior-channel leaks, adding tests and docs.

Changes

Declarative Topology Feature

Layer / File(s) Summary
ConsumerConfig topology fields and builders
consumer.go, consumer_test.go
Adds QueueConfig/Bindings fields, WithQueueConfig/WithBinding builders with defensive copying, exported BindingConfig type, and unit tests validating copy semantics.
Queue name resolution and topology application
consumer.go
NewConsumer resolves effective queue name from QueueConfig; setupChannel delegates to new applyTopology, guards installation against c.closed, and closes the replaced prior channel to prevent leaks.
Consume loop retry on missed reconnect signal
consumer.go
Adds consumeRetryDelay and a timer-based retry path in waitForReconnect so the consume loop no longer wedges without a reconnect signal.
Integration tests for topology and reconnect recovery
integration_test.go
Reworks publishUntilDelivered to retry against exchange/routing-key, and adds tests for declarative topology, topology restoration after reconnect, and recovery after queue deletion.
Changelog and README documentation
CHANGELOG.md, README.md
Documents the v0.5.0 release, declarative topology feature, and fixes.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NewConsumer
  participant setupChannel
  participant applyTopology
  participant Channel

  NewConsumer->>setupChannel: setup channel (initial or reconnect)
  setupChannel->>applyTopology: declare queue + apply bindings
  applyTopology->>Channel: QueueDeclare
  applyTopology->>Channel: QueueBind (per BindingConfig)
  applyTopology-->>setupChannel: resolved queue name
  setupChannel->>Channel: close prior channel if replaced
  setupChannel-->>NewConsumer: channel ready, c.queue updated
Loading

Possibly related PRs

  • KARTIKrocks/rabbitwrap#12: Both modify NewConsumer/setupChannel reconnect handling for server-named queues; this PR extends it to reapply declared queue/bindings on every setup.

Poem

A queue once lost upon reconnect,
Now rises whole, its bonds intact 🐰
Bindings copied, leaks all plugged,
No more stalls when signals lugged.
Hop along, declarative and neat!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The template sections are present but not filled in; Summary, Motivation, Changes, and Checklist need actual content and an issue reference. Populate each template section with a brief summary, motivation and Fixes # link, key changes, and checklist status.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main consumer topology and reconnect fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/consumer-reconnect-topology

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@codecov-commenter

codecov-commenter commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 40 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
consumer.go 20.00% 40 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@integration_test.go`:
- Around line 1995-1998: The test setup in
TestIntegration_ConsumeRecoversAfterQueueDeleted restores consumeRetryDelay too
early because Close() does not wait for the consumeLoop goroutine, which can
still be inside waitForReconnect. Update the test to keep the temporary retry
delay in place until the consume loop has fully exited, using a synchronization
point tied to the consumeLoop/handler lifecycle rather than only t.Cleanup.
Refer to consumeRetryDelay, Close, and consumeLoop when adjusting the teardown
ordering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b9604005-a93c-4dbf-9c5d-596cfd2fc120

📥 Commits

Reviewing files that changed from the base of the PR and between 01a326b and d8e2b72.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • README.md
  • consumer.go
  • consumer_test.go
  • integration_test.go

Comment thread integration_test.go Outdated
… data race

The wedge-recovery test shortened a package-global consumeRetryDelay and
restored it via t.Cleanup. Close() does not join the consumeLoop goroutine, so
a queue-delete cleanup could trigger one more waitForReconnect read of the
global concurrently with the restore write — a latent data race (timing-hidden
from -race in practice).

Replace the global with a per-Consumer retryDelay field, defaulted in
NewConsumer and set by the test before Start (goroutine creation gives the
happens-before edge). No shared mutable state remains, so there is nothing to
restore or race on teardown.
@KARTIKrocks
KARTIKrocks merged commit e78a6e8 into main Jul 5, 2026
11 checks passed
@KARTIKrocks
KARTIKrocks deleted the feat/consumer-reconnect-topology branch July 5, 2026 02:48
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