[rabbitmq-discuss] Can one consumer listen to 2 queues

Seshumadhav Chaturvedula smc.mobolt at gmail.com
Fri Sep 27 08:10:48 BST 2013



I configured producer to a fanout exchange and a queue, and same with 
consumer. For some reason special messages are not broadcasted, while each 
receiver randomly receives normal messages one at a time. Can someone help 
me the loophole in my approach. Am I doing something not supposed to ?

// My producerString fanExName = "myFanEx";String qName = "myQ";
// setup
channel.queueDeclare(qName, false, false, false, null);
channel.exchangeDeclare(fanExName, "fanout");
// usageif (isSpecialMessage(msg)) {
  channel.basicPublish(fanExName, "", null, message.getBytes());} else {
  channel.basicPublish("", qName, null, message.getBytes());}
---
// My consumerString fanExName = "myFanEx";String qName = "myQ";
// setup
channel.queueDeclare(qName, false, false, false, null);
channel.exchangeDeclare(fanExName, "fanout");QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(qName, true, consumer);
channel.queueBind(qName, fanExName, "");
// usagewhile (true) {
    QueueingConsumer.Delivery delivery = consumer.nextDelivery();
    ...}

Is there a better way of doing this. I dont want all messages to reach all 
recievers irrespective of type of message.

*Update*: I tried a different approach by using one fanout exchange + 2 
queues in worker In worker, I bound a standard queue "spl-q" and a 
generated (random) queue to bind to the same fanout exchange. I did 
channel.basicConsume(queue_name, true, consumer), for both queues

This also did not work
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130927/e757a84e/attachment.htm>


More information about the rabbitmq-discuss mailing list