<p></p>
<p>Hello,<br>
<br>
I have simple code like this to receive a message from a producer. I am sure from the documentation that the consumer will wait for a message. However, I would like to under what circumstances, the below code could result in a timeout exception and stop waiting for any more messages? For instance, the remote machine took some unreasonable time to send a response message and that the code below in the client side throw the exception.<br>
(like firewall, network issue etc)<br>
<br>
<br>
ConnectionFactory factory = new ConnectionFactory();<br>
factory.setHost("localhost");<br>
Connection connection = factory.newConnection();<br>
Channel channel = connection.createChannel();<br>
<br>
channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);<br>
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");<br>
<br>
channel.basicQos(1);<br>
<br>
QueueingConsumer consumer = new QueueingConsumer(channel);<br>
channel.basicConsume(TASK_QUEUE_NAME, false, consumer);<br>
<br>
while (true) {<br>
QueueingConsumer.Delivery delivery = consumer.nextDelivery();<br>
String message = new String(delivery.getBody());<br>
<br>
System.out.println(" [x] Received '" + message + "'"); <br>
doWork(message);<br>
System.out.println(" [x] Done" );<br>
<br>
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);<br>
}<br>
<br>
<br>
With thanks and regards<br>
Balachandar<br>
<br>
</p>