<div dir="ltr">Hello everyone,<div><br></div><div style>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:</div>
<div style><br></div><div style><div><span style="background-color:rgb(204,204,204)">while (true) {</span></div><div><span style="background-color:rgb(204,204,204)"><span class="" style="white-space:pre">        </span>QueueingConsumer.Delivery delivery = consumer.nextDelivery();</span></div>
<div><span style="background-color:rgb(204,204,204)"><span class="" style="white-space:pre">        </span>String message = new String(delivery.getBody());</span></div><div><span style="background-color:rgb(204,204,204)"><span class="" style="white-space:pre">        </span>System.out.println(" [x] Received '" + message + "'");</span></div>
<div><span style="background-color:rgb(204,204,204)">}</span></div><div><br></div><div style>However, I was unable to stop the Tomcat application by using the while loop (see my post @ <a href="http://stackoverflow.com/questions/14164517/trouble-stopping-a-tomcat-server-that-is-running-a-web-application-with-a-while">http://stackoverflow.com/questions/14164517/trouble-stopping-a-tomcat-server-that-is-running-a-web-application-with-a-while</a>).</div>
<div style><br></div><div style>Instead, I now use a Java ScheduledExecutorService which will call a consumer once every <i>x </i>milliseconds. </div><div style><br></div><div style><div><span style="background-color:rgb(204,204,204)">scheduler = Executors.newSingleThreadScheduledExecutor();</span></div>
<div><span style="background-color:rgb(204,204,204)">scheduler.scheduleAtFixedRate(new ScheduledConsumer(), 0, 15000, TimeUnit.MILLISECONDS);</span></div></div><div style><br></div><div style>I modified the consumer to only retrieve one individual message, using Channel.basicGet:</div>
<div style><br></div><div style><span style="background-color:rgb(204,204,204)">GetResponse response = channel.basicGet(queueName, autoAck);</span><br></div><div style><br></div><div style>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.</div>
<div style><br></div><div style>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.</div>
<div style><br></div><div style>My questions are as follows:</div><div style><ol style><li style>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?<br>
<br></li><li style>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?</li>
</ol><div><br></div><div style>I would appreciate any advice or suggestions.</div><div style><br></div><div style>Thanks!</div></div><div style><br></div><div style><br></div><div style><br></div><div style><span style="color:rgb(51,51,51);font-family:'Courier New',Courier,monospace;line-height:18px;white-space:nowrap"><br>
</span></div><div style><br></div></div><div style><br></div><div style><br></div></div>