0

I'm reading data from RabbitMQ (java client) in this way.

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

          System.out.println(message);

        }

Can I read all the data in the queue without while loop?

Anil Kumar
  • 2,521
  • 7
  • 23
  • 40

1 Answers1

0

Have you read the tutorials on the RabbitMQ website?

this looks like the basic java code for consuming messages:

Consumer consumer = new DefaultConsumer(channel) {
  @Override
  public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
  throws IOException {
    String message = new String(body, "UTF-8");
      System.out.println(" [x] Received '" + message + "'");
  }
};

channel.basicConsume(QUEUE_NAME, true, consumer);

this should send all messages to the specified consumer.

Derick Bailey
  • 72,004
  • 22
  • 206
  • 219