Skip to content

Add multi-routing-key bindings to RabbitMQ transport#9864

Merged
PascalSenn merged 10 commits into
ChilliCream:mainfrom
alisan3:ali/make-rmq-routing-keys-additive
Jun 7, 2026
Merged

Add multi-routing-key bindings to RabbitMQ transport#9864
PascalSenn merged 10 commits into
ChilliCream:mainfrom
alisan3:ali/make-rmq-routing-keys-additive

Conversation

@alisan3

@alisan3 alisan3 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Add multi-routing-key bindings to RabbitMQ transport

Summary

A RabbitMQ binding could previously carry only a single routing key. Binding one queue to several routing keys on the same exchange required declaring multiple bindings, which was verbose and did not reflect how RabbitMQ models bindings (one broker binding per routing key). This PR makes routing keys additive: a binding now holds a list of routing keys, and the transport provisions one broker binding per key between the source and destination.

What changed

  • New binding model: RabbitMQBindingConfiguration and RabbitMQBinding now expose a RoutingKeys collection instead of a single value. Provisioning iterates the keys and creates one QueueBind/ExchangeBind per key (falling back to an empty key when none are specified).
  • Fluent API:
    • RoutingKey(string) is now additive — each call accumulates a distinct key (with de-duplication) rather than overwriting.
    • RoutingKeys(params string[]) adds multiple keys in a single call; it delegates to RoutingKey, so both forms share one code path.
  • Diagram/describe output: link metadata now emits a routingKeys array (the old scalar routingKey field is gone); diagram.json for the demo was regenerated accordingly.

Backward compatibility

The previous single-key surface is preserved as [Obsolete] shims, so existing code keeps compiling:

  • RabbitMQBinding.RoutingKey (read) returns the first key, or empty string when none.
  • RabbitMQBindingConfiguration.RoutingKey (read/write) maps to the first key; setting it replaces the list, setting null clears it.

Both are annotated to be removed in a future release.

Tests

  • Unit (RabbitMQTopologyDescriptorTests): accumulation, de-duplication, declaring the same pair twice, and the obsolete property shims.
  • Integration (broker-backed via Testcontainers, RoutingKeyTests): topic/wildcard routing, negative (non-matching) routing, routing-key header propagation, and a combined test proving additivity end-to-end using both RoutingKeys(params) and chained RoutingKey().RoutingKey() declarations.

All RabbitMQ transport tests pass (299/299, including 18 broker-backed classes).

@CLAassistant

CLAassistant commented Jun 6, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@alisan3
alisan3 marked this pull request as ready for review June 7, 2026 06:41
Copilot AI review requested due to automatic review settings June 7, 2026 06:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds support for multiple routing keys per RabbitMQ binding, deprecating the single RoutingKey property while ensuring bindings can be provisioned for each configured key.

Changes:

  • Introduces RoutingKeys across binding configuration/runtime objects and provisions one broker binding per key.
  • Deprecates the single RoutingKey property while preserving backward-compatible read/write behavior.
  • Expands unit/integration coverage to validate accumulation, deduplication, and publish routing behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Topology/RabbitMQTopologyDescriptorTests.cs Adds tests for accumulating/deduplicating routing keys and obsolete property behavior.
src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/RoutingKeyTests.cs Adds integration test to ensure all bound routing keys receive messages.
src/Mocha/src/Mocha.Transport.RabbitMQ/Topology/RabbitMQBinding.cs Adds RoutingKeys to bindings and provisions one bind per key; obsoletes RoutingKey.
src/Mocha/src/Mocha.Transport.RabbitMQ/Topology/Descriptors/RabbitMQBindingDescriptor.cs Updates descriptor to accumulate/deduplicate keys; adds RoutingKeys(params) API.
src/Mocha/src/Mocha.Transport.RabbitMQ/Topology/Descriptors/IRabbitMQBindingDescriptor.cs Updates docs and adds a default RoutingKeys(params) convenience method.
src/Mocha/src/Mocha.Transport.RabbitMQ/Topology/Configurations/RabbitMQBindingConfiguration.cs Introduces RoutingKeys list and obsoletes RoutingKey with adapter semantics.
src/Mocha/src/Mocha.Transport.RabbitMQ/RabbitMQMessagingTransport.cs Updates transport description output from routingKey to routingKeys.
src/Mocha/examples/Demo/Demo.Catalog/diagram.json Updates diagram properties to use routingKeys.

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

Comment thread src/Mocha/src/Mocha.Transport.RabbitMQ/RabbitMQMessagingTransport.cs Outdated
Comment thread src/Mocha/src/Mocha.Transport.RabbitMQ/Topology/RabbitMQBinding.cs Outdated
Comment thread src/Mocha/src/Mocha.Transport.RabbitMQ/Topology/RabbitMQBinding.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants