3

I am trying to check whether a given rabbitmq queue is empty or not. For that i am trying to use:

channel.queueDeclarePassive(queueName).getMessageCount().

Using this I am always getting 0 as answer irrespective of number of messages shown by rabbitmqctl list_queues. There is no API available for this as far as i have searched.

I want same answer as given by rabbitmqctl list_queues.Please suggest a way to do that.

2
  • Try to use channel.queueDeclare instead Commented Feb 19, 2014 at 13:36
  • Tried with this also.. no luck.. still giving 0 as answer.. Commented Feb 20, 2014 at 9:09

2 Answers 2

6

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"
}
Sign up to request clarification or add additional context in comments.

2 Comments

I'm trying to do this, but it doesn't work for me. :( I can open ../api , also ../api/queues , but ../api/queues/vhost and ../api/queues/vhost/queue_name no. Do you know what can I try to make this work? You mentioned ,,you can enable the management plugin'' what his mean? Thanks!
http://localhost:15672/api/queues/%2f/hello - where 'hello' queue name, and '/' - vhost name
0

Use following url to access details via http api,

http://public-domain-name:15672/api/queues/%2f/queue_name

or use following command from localhost cli promt,

curl -i -u guest_uname:guest_password http://localhost:15672/api/queues/%2f/queue_name

Where, %2f is default vhost "/"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.