[Messenger] Add AMQP exchange to exchange bindings #46257
+42
−1
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.
Q/A
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 inamqp
transport. This feature uses\AMQPExchange::bind()
method already provided by the stub inphp-amqp/php-amqp
: https://github.com/php-amqp/php-amqp/blob/bb7611220e341039a7f5d72e606ca1e16eda4642/stubs/AMQPExchange.php#L22Example
messenger.yaml
:With the above configuration, the
Connection
class createssome_exchange
and binds it toanother_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:
In the above example (all the exchanges in this example are of the
topic
type):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 insymfony/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 withinamqp-messenger
seems reasonable to me.