you cannot get messages count using the SDK. channel.queueDeclarePassive(queueName).getMessageCount() is usually not correct because it won't count messages which waiting acknowledges.
you can enable the management plugin and query the queue by REST API:
http://localhost:15672/api/queues/vhost/queue_name
The response contains the total messages count as well as messages in handling/ready state. Access to "localhost:15672/api" to see more detail about how to call it.
Here is an example response of it on local server:
{
"memory":14680,
"message_stats":{
"publish":1,
"publish_details":{
"rate":0
}
},
"messages":1,
"messages_details":{
"rate":0
},
"messages_ready":1,
"messages_ready_details":{
"rate":0
},
"messages_unacknowledged":0,
"messages_unacknowledged_details":{
"rate":0
},
"idle_since":"2014-02-21 18:01:54",
"policy":"",
"exclusive_consumer_tag":"",
"consumers":0,
"backing_queue_status":{
"q1":0,
"q2":0,
"delta":[
"delta",
0,
0,
0
],
"q3":0,
"q4":1,
"len":1,
"pending_acks":0,
"target_ram_count":"infinity",
"ram_msg_count":1,
"ram_ack_count":0,
"next_seq_id":1,
"persistent_count":0,
"avg_ingress_rate":0,
"avg_egress_rate":0,
"avg_ack_ingress_rate":0,
"avg_ack_egress_rate":0
},
"status":"running",
"name":"01d99c41-7e08-4122-a7f3-c57d25a460f5",
"vhost":"/",
"durable":true,
"auto_delete":false,
"arguments":{
},
"node":"rabbit@SHACNG109WQPY"
}