Skip to content

Conversation

@danielkorytek
Copy link

@danielkorytek danielkorytek commented Dec 1, 2019

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR

This PR is adding possiblity to bind exchange to another exchange via transport configuration.

Example:

transports:
  first:
    dsn: 'amqp://'
    options:
      exchange:
        name: first_exchange
        type: topic
  second:
    dsn: 'amqp://'
    options:
      queues:
        second:
          binding_keys:
            - 'key.*'
      exchange:
        name: second_exchange
        type: topic
        bindings:
          first_exchange:
            binding_keys: #optional
              - '*'
            binding_arguments: [] #optional

In this example, we binding second_exchange to first_exchange with optional binding_keys and binding_arguments.

If message will be published on first_exchange, second_exchange will also have that message, and could be consumed by second transport worker.

@danielkorytek danielkorytek requested a review from sroze as a code owner December 1, 2019 10:53
@danielkorytek danielkorytek force-pushed the messenger/amqp_bing_exchange_to_another_exchange branch from 9f4b69f to cfa77e6 Compare December 1, 2019 13:20
@nicolas-grekas nicolas-grekas added this to the next milestone Dec 2, 2019
@danielkorytek danielkorytek force-pushed the messenger/amqp_bing_exchange_to_another_exchange branch 2 times, most recently from 87bad8c to d4e0367 Compare December 3, 2019 21:17
@danielkorytek danielkorytek force-pushed the messenger/amqp_bing_exchange_to_another_exchange branch from d4e0367 to e2b0920 Compare December 11, 2019 20:38
@danielkorytek danielkorytek force-pushed the messenger/amqp_bing_exchange_to_another_exchange branch from e2b0920 to 8f89e3c Compare December 20, 2019 10:06
@Nyholm
Copy link
Member

Nyholm commented Jan 19, 2020

Thank you for this PR.

Could you help me understand why you want to bind one exchange to another? With the little AMQP I know, I can only believe that this is only for very advanced use cases, right?

What Im currently considering is, if this is a feature we say it to advanced/rare... Any maybe it should be better if you configured this AMQP routing with AMQP tools instead.

Please help me understand this better. What is the scenarios this feature is useful?

@Tobion
Copy link
Contributor

Tobion commented Jan 28, 2020

Please explain the use-case. I also don't see the need yet for this in symfony messenger config. It can be solved in user-land.

@fabpot
Copy link
Member

fabpot commented Feb 11, 2020

Closing as there is no feedback. Feel free to add a use case so that we can discuss this PR further. Thank you.

@fabpot fabpot closed this Feb 11, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
fabpot added a commit 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
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.

6 participants