Hi,<div><br></div><div>As per your suggestion, I created 5 channels as follows:</div><div><br></div><div><div>for (int i = 0; i < 5; i++) {</div><div> final Channel channel = connection.createChannel();</div>
<div> channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null);</div><div> channel.basicQos(1);</div><div><br></div><div> <a href="http://log.info">log.info</a>(" [x] Awaiting RPC requests");</div>
<div> </div><div> boolean autoAck = false;</div><div> channel.basicConsume(RPC_QUEUE_NAME, autoAck, "watermark" + i,</div><div> new DefaultConsumer(channel) {</div>
<div><br></div><div> @Override</div><div> public void handleDelivery(String consumerTag,</div><div> Envelope envelope,</div><div> AMQP.BasicProperties properties,</div>
<div> byte[] body)</div><div> throws IOException {</div><div> String routingKey = envelope.getRoutingKey();</div><div> String contentType = properties.getContentType();</div>
<div> long deliveryTag = envelope.getDeliveryTag();</div><div> //process the message here</div><div> channel.basicPublish("", properties.getReplyTo(),</div>
<div> new BasicProperties.Builder().correlationId(properties.getCorrelationId()).build(),</div><div> response.getBytes("UTF-8"));</div><div>
channel.basicAck(deliveryTag, false);</div>
<div> }</div><div> });</div><div> </div><div> }</div><div><br></div><div>But, the consumer doesn't seem to listen to the queue, as soon as I run this application, it exists. Earlier I used the while(true) loop to get the messages. How do I make sure if the consumer listens to the intended queue and process messages?</div>
<div><br></div><div><br></div><div>-Mahesh</div><br><div class="gmail_quote">On Mon, Aug 27, 2012 at 6:54 PM, Matthias Radestock <span dir="ltr"><<a href="mailto:matthias@rabbitmq.com" target="_blank">matthias@rabbitmq.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Mahesh,<div class="im"><br>
<br>
On 27/08/12 13:37, Mahesh Viraktamath wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
I read the API guide and still stuck to the QueuingConsumer, for each<br>
incoming message I create a new service thread (with common channel,<br>
without that the service won't know which message to acknowledge). But<br>
in the guide, it is mentioned that the channel should be created for<br>
each thread. Now, my question is does this guide assumes that we run<br></div>
different consumer threads? *I can't understand the concept of different<br>
consumer threads*. I run a single consumer and use basicConsume() to<div class="im"><br>
listen to the messages and each message (nextDelivery()) will give rise<br>
to a new service thread. Again, each message creating a thread is scary !<br>
<br>
If it helps, I am running the consumer as a java application and use<br>
basicConsume() and nextDelivery() in a while loop to process the<br>
messages. Our application sends messages to these non-stop. So, I am<br>
looking for a consumer which will not block the incoming messages when<br>
it is processing a large message.<br>
</div></blockquote>
<br>
I suggest you create N channels and for each channel:<br>
- set the basic.qos prefetch to 1 or some other low-ish value (for fair dispatch)<br>
- create a consumer as shown in <a href="http://www.rabbitmq.com/api-guide.html#consuming" target="_blank">http://www.rabbitmq.com/api-<u></u>guide.html#consuming</a><br>
<br>
You write above that you only have one channel because "without that the service won't know which message to acknowledge", but the channel is accessible via the context (as shown in the example), so there is no ambiguity.<br>
<br>
Obviously message ordering goes out of the window, but that's the case for any scheme where messages are handled by multiple threads.<br>
<br>
Regards,<br>
<br>
Matthias.<br>
</blockquote></div><br></div>