Skip to content

feat(rabbitmq): support per-exchange bindings in RabbitSubscribe#1152

Merged
underfisk merged 3 commits intomasterfrom
copilot/add-exchange-per-routing-key
Mar 17, 2026
Merged

feat(rabbitmq): support per-exchange bindings in RabbitSubscribe#1152
underfisk merged 3 commits intomasterfrom
copilot/add-exchange-per-routing-key

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

Currently @RabbitSubscribe only supports binding a queue to a single exchange, even when multiple routing keys are specified. This adds a bindings option that allows binding one queue to routing keys across multiple exchanges in a single handler.

Changes

  • rabbitmq.interfaces.ts — New RabbitSubscribeBinding interface (exchange, routingKey); adds bindings?: RabbitSubscribeBinding[] to MessageHandlerOptions with JSDoc
  • connection.tssetupQueue() processes the bindings array and calls channel.bindQueue() for each entry; fully additive alongside existing exchange/routingKey behavior
  • docs/modules/rabbitmq.md — New "Binding a Queue to Multiple Exchanges" section with usage examples
  • E2E tests — Three new tests covering: first-exchange binding, second-exchange binding, and both simultaneously

Usage

@RabbitSubscribe({
  queue: 'my-queue',
  bindings: [
    { exchange: 'exchange1', routingKey: 'route.a' },
    { exchange: 'exchange2', routingKey: 'route.b' },
  ],
})
async handleMessages(msg: object) { ... }

bindings can be combined with the top-level exchange/routingKey — both sets of bindings are applied. Fully backward-compatible.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • mise.run
    • Triggering command: /usr/bin/curl curl -sSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>rabbitmq: support specifying exchange per routing key in RabbitSubscribe</issue_title>
<issue_description>Allow specifying the exchange name per routingKey in RabbitSubscribe to allow or binding the queue to routing keys from multiple exchanges</issue_description>

<agent_instructions>Are you able to implement the feature request in our nestjs rabbitmq package?

If possible, add documentation in our docs/rabbitmq markdown file , JSDoc around the module/types and e2e tests</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…Subscribe via bindings option

Co-authored-by: underfisk <15980884+underfisk@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for specifying exchange per routing key in RabbitSubscribe feat(rabbitmq): support per-exchange bindings in RabbitSubscribe Mar 17, 2026
Copilot AI requested a review from underfisk March 17, 2026 12:49
@underfisk underfisk marked this pull request as ready for review March 17, 2026 13:18
Copilot AI review requested due to automatic review settings March 17, 2026 13:18
@underfisk underfisk merged commit 48557d8 into master Mar 17, 2026
6 checks passed
@underfisk underfisk deleted the copilot/add-exchange-per-routing-key branch March 17, 2026 13:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for binding a single subscriber queue to routing keys across multiple exchanges via a new bindings option on @RabbitSubscribe, enabling multi-exchange consumption in one handler while keeping existing exchange/routingKey behavior intact.

Changes:

  • Introduces RabbitSubscribeBinding and bindings?: RabbitSubscribeBinding[] on MessageHandlerOptions.
  • Extends queue setup to apply multiple channel.bindQueue() calls based on bindings (in addition to existing exchange/routingKey binding).
  • Adds documentation and E2E coverage for multi-exchange bindings.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/rabbitmq/src/rabbitmq.interfaces.ts Adds the binding shape (RabbitSubscribeBinding) and the new bindings option to handler options with JSDoc.
packages/rabbitmq/src/amqp/connection.ts Applies per-binding queue bindings during setupQueue() by iterating bindings.
integration/rabbitmq/e2e/subscribe.e2e-spec.ts Adds E2E scenarios verifying messages are received from each exchange binding and both combined.
docs/modules/rabbitmq.md Documents how to bind a single queue to routing keys across multiple exchanges using bindings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +1125 to +1134
await Promise.all(
bindings.map(({ exchange: bindingExchange, routingKey: bindingKey }) =>
channel.bindQueue(
actualQueue as string,
bindingExchange,
bindingKey,
bindQueueArguments,
),
),
);
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.

rabbitmq: support specifying exchange per routing key in RabbitSubscribe

3 participants