Topic exchange ambiguity with RabbitMQ

时光总嘲笑我的痴心妄想 提交于 2019-12-06 08:36:26

First thing first : Exchange do not deliver to Consumer. It delivers messages to Queue for matching routing kyes.

      1. For a typical topic exchange set up; how many queues do you need?

If you have multiple consumer then you will need one queue for every consumer.

      2. Can my consumers get away with just exchange binding, or does it have to include queue interaction?

You need to bind consumer with queue, if queue not exist then create and bind.

      3. Is it possible for a single message to appear in 2 consumers with topic exchange (or do you need fanout for that)?

YES, Only if the consumer have their own (separate queue bind with same routing key).Otherwise it will be Round Robin way.

So best way is to have consumer's own queue with required routing key...!!!

For a typical topic exchange set up; how many queues do you need?

It depends on your application needs. You may start from just one queue to implement simple FIFO stack and later add more queues with for more granulated messages consuming.

Can my consumers get away with just exchange binding, or does it have to include queue interaction?

The idea of AMQP exchanges is to get published messages and put them to one or more queues (or even other exchanges or drop at all under certain condition). Consumer works only with queues, while publisher works only with exchanges.

There might be some misunderstandings with Default Exchange while it route messages to the queue name same as a routing key and it sometimes interpreted as publishing to queues which is not true.

Is it possible for a single message to appear in 2 consumers with topic exchange (or do you need fanout for that)?

I guess you are talking about duplicating one message to multiple queues (while there are some erroneous situations when you really may have single message being processed by multiple consumers).

If so - sure. You can just create multiple bindings for queue to get different messages. Here is small example:

Let you have three messages published to topic exchange with three different routing keys customer.appA.created, customer.appB.created and `customer.appC.created.

You can create separate queue to collect specific messages by binding queue with exact routing key - customer.appA.created, customer.appB.created and so on, or as you already noted, bind queue with wildcard routing key customer.*.created.

To collect messages only for appA and appB you can create queue with two bindings customer.appA.created and customer.appB.created, so you'll get two messages type in one queue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!