You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -466,6 +466,42 @@ public function indexAction($name)
466
466
467
467
Is very similar to the previous example, we just have an extra `addRequest` call. Also we provide meaningful request identifiers so later will be easier for us to find the reply we want in the __$replies__ array.
468
468
469
+
### Multiple Consumers ###
470
+
471
+
It's a good practice to have a lot of queues for logic separation. With a simple consumer you will have to create one worker (consumer) per queue and it can be hard to manage when dealing
472
+
with many evolutions (forget to add a line in your supervisord configuration?). This is also useful for small queues as you may not want to have as many workers as queues, and want to regroup
473
+
some tasks together without losing flexibility and separation principle.
474
+
475
+
Multiple consumers allow you to handle this use case by listening to multiple queues on the same consumer.
476
+
477
+
Here is how you can set a consumer with multiple queues:
478
+
479
+
```yaml
480
+
multiple_consumers:
481
+
upload:
482
+
connection: default
483
+
exchange_options: {name: 'upload', type: direct}
484
+
queues:
485
+
upload-picture:
486
+
name: upload_picture
487
+
callback: upload_picture_service
488
+
routing_keys:
489
+
- picture
490
+
upload-video:
491
+
name: upload_video
492
+
callback: upload_video_service
493
+
routing_keys:
494
+
- video
495
+
upload-stats:
496
+
name: upload_stats
497
+
callback: upload_stats
498
+
```
499
+
500
+
The callback is now specified under each queues and must implement the `ConsumerInterface` like a simple consumer.
501
+
All the options of `queues-options` in the consumer are available for each queue.
502
+
503
+
Be aware that all queues are under the same exchange, it's up to you to set the correct routing for callbacks.
504
+
469
505
### Anonymous Consumers ###
470
506
471
507
Now, why will we ever need anonymous consumers? This sounds like some internet threat or something… Keep reading.
0 commit comments