Commit 46098d2
committed
feature symfony#46257 [Messenger] Add AMQP exchange to exchange bindings (Samik081)
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: symfony#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:

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 bindingsFile tree
3 files changed
+71
-1
lines changed- src/Symfony/Component/Messenger
- Bridge/Amqp
- Tests/Transport
- Transport
3 files changed
+71
-1
lines changedLines changed: 57 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
396 | | - | |
| 396 | + | |
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
421 | 477 | | |
422 | 478 | | |
423 | 479 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| |||
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
143 | 147 | | |
144 | 148 | | |
145 | 149 | | |
| |||
460 | 464 | | |
461 | 465 | | |
462 | 466 | | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
463 | 476 | | |
464 | 477 | | |
465 | 478 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
0 commit comments