Skip to content

[Messenger] Add AMQP exchange to exchange binding reference#16783

Merged
javiereguiluz merged 1 commit intosymfony:7.4from
Samik081:amqp-exch2exch-binding-docs
Mar 13, 2026
Merged

[Messenger] Add AMQP exchange to exchange binding reference#16783
javiereguiluz merged 1 commit intosymfony:7.4from
Samik081:amqp-exch2exch-binding-docs

Conversation

@Samik081
Copy link
Contributor

@Samik081 Samik081 commented May 4, 2022

@carsonbot carsonbot added this to the 6.1 milestone May 4, 2022
@wouterj wouterj modified the milestones: 6.1, next May 4, 2022
@wouterj wouterj added the Waiting Code Merge Docs for features pending to be merged label May 4, 2022
@Samik081 Samik081 force-pushed the amqp-exch2exch-binding-docs branch from ebf629c to 801bcf8 Compare May 23, 2022 09:48
@Samik081 Samik081 changed the base branch from 6.1 to 6.2 May 23, 2022 09:49
@Samik081 Samik081 force-pushed the amqp-exch2exch-binding-docs branch from 801bcf8 to 6477337 Compare May 31, 2022 08:52
@Samik081 Samik081 force-pushed the amqp-exch2exch-binding-docs branch from 6477337 to bc19829 Compare June 14, 2022 09:59
@Samik081 Samik081 force-pushed the amqp-exch2exch-binding-docs branch from bc19829 to e3f18ed Compare August 3, 2022 14:28
@Samik081 Samik081 force-pushed the amqp-exch2exch-binding-docs branch from e3f18ed to 1ebd353 Compare January 4, 2023 12:15
@Samik081 Samik081 requested a review from xabbuh as a code owner January 4, 2023 12:15
@Samik081 Samik081 changed the base branch from 6.2 to 6.3 January 4, 2023 12:16
@Samik081 Samik081 force-pushed the amqp-exch2exch-binding-docs branch from 1ebd353 to 75b60c6 Compare September 4, 2025 09:51
@Samik081 Samik081 requested a review from OskarStark as a code owner September 4, 2025 09:51
@Samik081 Samik081 changed the base branch from 6.3 to 7.4 September 4, 2025 09:52
@Samik081 Samik081 force-pushed the amqp-exch2exch-binding-docs branch from 75b60c6 to 0f644ca Compare September 8, 2025 08:21
fabpot added a commit to symfony/symfony that referenced this pull request Sep 17, 2025
…mik081)

This PR was squashed before being merged into the 7.4 branch.

Discussion
----------

[Messenger] Add AMQP exchange to exchange bindings

## Q/A
| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | symfony/symfony-docs#16783

## Changes description
This PR introduces very similar changes to this one: #34737, which was closed due to the lack of the feedback.
I'd like to continue this topic, share the missing feedback and discuss it further if needed.

I have introduced the possibility to configure `exchange-to-exchange` bindings in `amqp` transport. This feature uses `\AMQPExchange::bind()` method already provided by the stub in `php-amqp/php-amqp`: https://github.com/php-amqp/php-amqp/blob/bb7611220e341039a7f5d72e606ca1e16eda4642/stubs/AMQPExchange.php#L22

Example `messenger.yaml`:
```yaml
framework:
    messenger:
        transports:
            some_transport:
                dsn: 'amqp://'
                options:
                    exchange:
                        type: topic
                        name: some_exchange
                        bindings: # added configuration
                            another_exchange:
                                binding_keys:
                                    - key1
                                    - key2
                                binding_arguments:
                                    x-match: all
```
With the above configuration, the `Connection` class creates `some_exchange` and binds it to `another_exchange` using `['key1', 'key2']` keys and `[x-match =>'all']` arguments.

## Reasoning

Binding an exchange to an exchange feature can be used to create more complex RabbitMQ topologies. It is also briefly described here: https://www.cloudamqp.com/blog/exchange-to-exchange-binding-in-rabbitmq.html

A real-world example could be kind of RabbitMQ publisher/subscriber pattern implementation between microservices, that could be visualized as follows:

![rabbitmq](https://user-images.githubusercontent.com/13415865/166811854-7d8b50e9-85c4-448c-a514-1449b3778cae.png)

In the above example (all the exchanges in this example are of the `topic` type):
```
App `Foo` publishes events to its own exchange AND subscribes to the events that app `Bar` publishes on its exchange.
App `Bar` publishes events to its own exchange AND subscribes to the events that app `Foo` publishes on its exchange.
App `...` subscribes to the events that apps `Foo` and `Bar` publish on their exchanges.
```

This approach might have few advantages, such as easier maintainability, dependency management and monitoring, or better separation between microservices.

### My thoughts
I feel that the fact, that https://github.com/php-amqp/php-amqp has `\AMQPExchange::bind()` implemented is already sufficient reason to have this supported in `symfony/amqp-messenger`. I am aware this feature might be rarely used, but it's already there in the extension, and having the ability to use it within `amqp-messenger` seems reasonable to me.

Commits
-------

9fd9049 [Messenger] Add AMQP exchange to exchange bindings
@javiereguiluz javiereguiluz removed the Waiting Code Merge Docs for features pending to be merged label Mar 13, 2026
@javiereguiluz javiereguiluz modified the milestones: next, 7.4 Mar 13, 2026
@javiereguiluz javiereguiluz force-pushed the amqp-exch2exch-binding-docs branch from 3f27efd to 1b17350 Compare March 13, 2026 08:02
@javiereguiluz
Copy link
Member

Szymon, thanks a lot for this contribution ... and we're sorry it took us so long to merge it.

@javiereguiluz javiereguiluz merged commit 11cf0d7 into symfony:7.4 Mar 13, 2026
3 checks passed
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