[rabbitmq-discuss] Consumer Clients as Tomcat Web Applications and Work Queue Configuration

Kevin Behr behrk2 at gmail.com
Thu Jan 31 01:33:18 GMT 2013


Hello everyone,

I have five RabbitMQ consumer clients that are written and deployed as
Tomcat web applications.  My original intention was to consume messages in
the typical fashion:

while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
 String message = new String(delivery.getBody());
System.out.println(" [x] Received '" + message + "'");
}

However, I was unable to stop the Tomcat application by using the while
loop (see my post @
http://stackoverflow.com/questions/14164517/trouble-stopping-a-tomcat-server-that-is-running-a-web-application-with-a-while
).

Instead, I now use a Java ScheduledExecutorService which will call a
consumer once every *x *milliseconds.

scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new ScheduledConsumer(), 0, 15000,
TimeUnit.MILLISECONDS);

I modified the consumer to only retrieve one individual message,
using Channel.basicGet:

GetResponse response = channel.basicGet(queueName, autoAck);

This workaround has been working for me without any problems.  However, I'm
starting to wonder if I am going about it all wrong.  You see, I now need
to set up a work queue model, so that I can scale my resources and deploy
additional consumers as the need arises.  So I could spin up a new Tomcat
server and deploy my consumer .war files, and voila.  But it was brought to
my attention that by using Channel.basicGet, I am not in fact truly
consuming - messages are not being pushed down.  I am instead "pulling"
messages.

Therefore, I assume that my consumers will not enjoy the luxury of fair,
round robin dispatching.  Consumer client "A" might retrieve more messages
than consumer client "B", solely because of the fixed rate at which it was
set to consume.

My questions are as follows:

   1. Is it a bad idea to deploy consumers as Tomcat web applications?  Are
   there any advantages or disadvantages as compared to the alternative of
   running system level Java clients?

   2. In the case of work queues, am I better off retrieving messages that
   are pushed down to my clients, and setting a prefetchCount
   (channel.basicQos(1)) to ensure that I only receive one message at a time?


I would appreciate any advice or suggestions.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130130/f5b4c38c/attachment.htm>


More information about the rabbitmq-discuss mailing list