[rabbitmq-discuss] Count message without Ack on a queue

bloodBaron bloodbaronofvizkopa at gmail.com
Thu Aug 7 16:02:33 BST 2014


Under AMQImpl.Queue.DeclareOk class, getMessageCount() will return the number
of messages on a queue.
In java, getMessageCount() doesn't count the messages which haven't receive
an Ack yet, but if I use [rabbitmqctl list_queues name messages] in tht
terminal, I can see those messages who are consumed by a QueueingConsumer
without receiving a ack back.

E.G.,
Assume I've already put 1 message on the queue.

DeclareOk queue= channel.queueDeclare("queue" false, false, true, null);
QueueingConsumer consumer = new QueueingConsumer(channel);
// The server should expect explicit acknowledgements.
channel.basicConsume(queue.getQueue(), false, consumer);

while(true) {
    QueueingConsumer.Delivery delivery = consumer.nextDelivery();
    System.out.println("Received '[" + routingKey + "':'" + message + "]");

    // Do not send an Ack back.
    //channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
   
    queue= channel.queueDeclare("queue" false, false, true, null);
    // System will print 0 here, which means it can't see this message on
the queue.
    System.out.println(queue.getMessageCount());
}

If I use "rabbitmqctl list_queues name messages" after I run the above code
in terminal, I get the following result:
queue 1
This means rabbitmqctl can count the message which hasn't received an Ack
yet.

Is there a way we can use to count the messages without Ack  in Java except
by calling rabbitmqctl in Java?



--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/Count-message-without-Ack-on-a-queue-tp36959.html
Sent from the RabbitMQ mailing list archive at Nabble.com.


More information about the rabbitmq-discuss mailing list