[rabbitmq-discuss] Possible causes for timeout in rabbitMQ

Balachandar R.A. balachandar.ra at gmail.com
Mon May 20 12:22:09 BST 2013


Hello,

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.
 (like firewall, network issue etc)


    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    channel.basicQos(1);

    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(TASK_QUEUE_NAME, false, consumer);

    while (true) {
      QueueingConsumer.Delivery delivery = consumer.nextDelivery();
      String message = new String(delivery.getBody());

      System.out.println(" [x] Received '" + message + "'");
      doWork(message);
      System.out.println(" [x] Done" );

      channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
    }


With thanks and regards
Balachandar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130520/be494f9a/attachment.htm>


More information about the rabbitmq-discuss mailing list