[rabbitmq-discuss] Consuming from multiple queues

Ilya Sterin sterini at gmail.com
Tue Jan 26 22:18:45 GMT 2010


Sorry, the cleanupAndReestablishConnectionsFor.... shouldn't be there.
 So ignore that line.

Ilya

On Tue, Jan 26, 2010 at 5:17 PM, Ilya Sterin <sterini at gmail.com> wrote:
> I have a rather standard publish/subscriber architecture, where
> publisher publishes messages into numerous queues.  Queues store
> distinct message types.
>
> The consumer currently connects to a single queue and processes these
> messages.  I spin off multiple consumers, so each queue has at least
> one consumer bound and awaiting messages.  A consumer is a distinct
> thread, though say if I have 10 threads listening on a queue, these
> threads are all blocking even though no deliveries are made to this
> queue.
>
> Although these threads are in wait mode and due not utilize any CPU,
> I'd much prefer to put them to use.  So my question is, how can a
> single consumer listen to multiple queues and process messages as they
> arrive on either of the queues.  I don't care about the distinction
> between queues on the consumer side, but I do on the producer side as
> well as for other monitoring purposes.
>
> I currently have something in the likes of... (I picked out bits and
> pieces from my abstraction, so I might of missed something here)
>
> ############
> Channel channel = conn.createChannel();
> QueueingConsumer consumer = new QueueingConsumer(channel);
> channel.basicConsume(queueName, false, consumer);
>
> while (!Thread.currentThread().isInterrupted()) {
>      QueueingConsumer.Delivery delivery;
>      try {
>        delivery = consumer.nextDelivery();
>      }
>      catch (InterruptedException e) {
>        LOG.warn("Thread interrupted: ", e);
>        channel =
> cleanupAndReestablishConnectionsFor(delivery.getProperties().get);
>        continue;
>      }
>      .... do something with message and acknowledge it if OK
> }
>
> #############
>
> I can't seem to find documentation related to this.  Is this possible?
>
> Thanks.
>
> Ilya
>




More information about the rabbitmq-discuss mailing list