0
votes

I have trouble understanding the routing in RabbitMQ. Consider I have several producers (let call them clients) that produce messages to the queue. E.g., clients A, B, and C send messages to queue X1.

Let the consumer respond to all messages sending responses back to the queue. E.g., consumer gets message from queue X1, does something, and sends responses to the queue X1.

How can, client A determine where are in the queue X1 messages sent to it and where are messages sent to clients B or C?

I can't declare one queue per connection because of large number of connections expected (~10^6). So I'm in trouble here. Any suggestions? Thanks.

1
I suggest you remove the routing tag. You are referring to routing in MQ and not network routing. They are not the same thing and the routing the tag refers to is network routing.robthewolf
I cannot make sense of your question here. I am not sure the relevance of X2 to the rest of the question, similarly with D E and F. I also think you might need to re read the tutorials on the RabbitMQ website because routing only really happens when your producers send to and exchange and the consumers consume from a queue that is bound to that exchange.robthewolf
I read a bunch of tutorials about AMQP and RabbitMQ itself. To make it clear: forget about clients D, E, F and queue X2. Three clients A, B, C send messages to the exchange with amq.topic type. Those three messages routes to queue X1. Consumer process all messages and send responces back to this exchange. Responces routes to queue X1. Now each of three clients need to get it message from the queue. So client A wants message sent to it, client B - message sent by consumer to B, etc. How this can be done?maverik
I think you should rewrite your question instead of posting such a big change in your commentrobthewolf

1 Answers

2
votes

I think you need to look at the RPC tutorial. From your description it sounds like that is what you want to do. However that would probably require you to declare more queues than you want.

Approaching this a different way. I cannot understand why you would send a reply back to the producer not only by the same exchange but the same queue that the consumers are consuming from.

Would it not make sense to have producers P1,P2 and P3 send to exchange X1 with routing key "abc.aaa.xyz" / "abc.bbb.xyz" / "abc.ccc.xyz". Then have queues Q1, Q2 and Q3 bound to X1 with binding keys ".aaa." / ".bbb." / ".ccc." or just Q1 with binding key "abc.*.xyz" (I am unclear on exactly what you want so just making some suggestions). Which are consumed by Consumers C1, C2 and C3

When the Consumer has finished processing the message then it will send a message to X2, with routing key that identifies itself. The producers will consume from queues bound to X2.

The point I am trying to make is that you do not want more than one consumer reading from a queue. There is only one case in which you want that and that is a task queue. I am not clear on your use case so you may want a task queue. If you do then you should still not have your producers reading from the same task queue as your consumers. Aside from task queues you should have one consumer read from one queue. You may have many queues to one exchange and even many bindings from one queue to one exchange.

I hope this helps