feat!: add AMQPSession with reconnection and high-level queue/exchange API#186
Merged
feat!: add AMQPSession with reconnection and high-level queue/exchange API#186
Conversation
415dc68 to
e504ec0
Compare
baelter
commented
Feb 27, 2026
baelter
commented
Feb 27, 2026
baelter
commented
Feb 27, 2026
baelter
commented
Feb 27, 2026
baelter
commented
Feb 27, 2026
549e2a2 to
d30970e
Compare
3c969ec to
4b4f5b2
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
antondalgren
reviewed
Mar 3, 2026
antondalgren
approved these changes
Mar 4, 2026
…e API
Introduces AMQPSession as the recommended high-level entry point for
applications that need automatic reconnection and consumer recovery.
New classes and types:
- AMQPSession.connect(url, options?) — picks TCP or WebSocket transport
from the URL scheme; reconnects with configurable exponential backoff
- AMQPQueue — reconnect-safe queue handle: publish(), subscribe(), get(),
bind(), unbind(), purge(), delete()
- AMQPExchange — reconnect-safe exchange handle: publish(), bind(),
unbind(), delete()
- AMQPSubscription / AMQPGeneratorSubscription — stable consumer handles
that survive reconnection; generator variant is AsyncIterable<AMQPMessage>
- QueueSubscribeParams — ConsumeParams + prefetch? for per-consumer QoS
- QueuePublishOptions / ExchangePublishOptions — AMQPProperties extended
with confirm? (and routingKey? for exchanges); replaces separate
positional args and publishAndForget()
- ondisconnect hook on AMQPBaseClient (TCP and WebSocket)
Publish API: queue.publish(body, { confirm, contentType, … }) and
exchange.publish(body, { routingKey, confirm, contentType, … }).
Shared publish logic lives in module-level functions (publishConfirmed /
publishNoConfirm) — no inheritance.
Exchange shortcuts on session: directExchange(), fanoutExchange(),
topicExchange(), headersExchange().
Breaking changes (v3 → v4):
- AMQPChannel.queue() removed; use ch.queueDeclare() or session.queue()
- AMQPQueue is now session-only; no longer returned by channel methods
- AMQPQueue no longer re-exported from AMQPClient / AMQPWebSocketClient
1df91ef to
3d0913f
Compare
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.
Summary
Introduces `AMQPSession` as the recommended high-level entry point for applications that need automatic reconnection and consumer recovery. Separates the API into two clear layers:
New
Breaking changes
Architecture
`AMQPSession` is a thin connection/reconnection manager. It exposes only `queue()`, `exchange()`, and the exchange shorthand factories as public API — everything else is either private or `@internal`.
Shared publish logic lives in module-level functions (`publishConfirmed` / `publishNoConfirm` in `amqp-publisher.ts`). `AMQPQueue` and `AMQPExchange` each hold their own `session` reference and call those functions directly — no inheritance.
`AMQPQueue` owns its subscriptions. It opens a dedicated channel per consumer, tracks subscriptions in a private `Set`, and has `@internal` `recover()` and `cancelAll()` methods that the session calls on reconnect and stop respectively. The session tracks queues (not individual subscriptions) and delegates recovery to each queue.
Other fixes
Test plan