문제

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.

도움이 되었습니까?

해결책

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"
}

다른 팁

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 "/"

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top