[rabbitmq-discuss] To know when a queue is empty from a Java client

Michael Bridgen mikeb at rabbitmq.com
Thu Aug 26 15:45:08 BST 2010


> So if declare_ok always refers to a new queue, we have no choice but use 
> Runtime.exec("rabbitmqctl list_queues") if we want to know this kind of 
> information on an existing queue? 

No, queue.declare_ok does not always refer to a new queue.

If you don't supply a name to queue.declare, the server will construct a 
fresh name, and the responding queue.declare_ok will refer to a new 
queue.  If you *do* supply a name, and the queue already exists, then 
queue.declare_ok will refer to that queue.

Using a passive queue.declare means you only need supply the name of the 
queue.  In recent versions of the Java library, it's a separate method 
in ChannelN.

Cheers,
Michael

> 
>     --- En date de : *Jeu 26.8.10, Simon MacMullen
>     /<simon at rabbitmq.com>/* a écrit :
> 
> 
>         De: Simon MacMullen <simon at rabbitmq.com>
>         Objet: Re: [rabbitmq-discuss] To know when a queue is empty from
>         a Java client
>         À: rabbitmq-discuss at lists.rabbitmq.com
>         Date: Jeudi 26 août 2010, 16h13
> 
>         On 26/08/10 15:05, Florence Chabanois wrote:
>          > Thanks for your answer !
>          >
>          > We may be using it in a wrong way but so far, the method
>          > getMessageCount() always displays 0 message, when /"rabbitmqctl
>          > list_queues"/ displays 8 messages or keeps growing.
>          >
>          >     DeclareOk declareOk = channel.queueDeclare();
> 
>         That's declaring a *new* server-named queue - which has 0
>         messages in
>         it. Is that literally your code, or a paraphrase?
> 
>         Cheers, Simon
> 
>          >     System.out.println(">>>> MESSAGES : " +
>         declareOk.getMessageCount());
>          >
>          >
>          > Cheers,
>          > Florence.
>          >
>          > --- En date de : *Jeu 26.8.10, Michael Bridgen
>         /<mikeb at rabbitmq.com>/* a
>          > écrit :
>          >
>          >
>          >     De: Michael Bridgen <mikeb at rabbitmq.com>
>          >     Objet: Re: [rabbitmq-discuss] To know when a queue is
>         empty from a
>          >     Java client
>          >     À: flocha2000-agile at yahoo.fr
>          >     Cc: rabbitmq-discuss at lists.rabbitmq.com
>          >     Date: Jeudi 26 août 2010, 15h24
>          >
>          >      > From a Java client we need to know when a queue is empty.
>          >      > Is there a way to know it via the Java api (or to know
>         the number
>          >      > of messages in a queue).
>          >      >
>          >      > We would rather have another way than calling
>         /"rabbitmqctl
>          >     list_queues"/
>          >      > via Runtime.exec()
>          >
>          >     A queue.declare_ok frame includes the number of messages
>         on the
>          >     queue; so, you could send a passive queue.declare, and
>         examine the
>          >     response.
>          >
>          >     Regards,
>          >     Michael
>          >
>          >
>          >
>          >
>          > _______________________________________________
>          > rabbitmq-discuss mailing list
>          > rabbitmq-discuss at lists.rabbitmq.com
>          >
>         https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
> 
> 
>         -- 
>         Simon MacMullen
>         Staff Engineer, RabbitMQ
>         SpringSource, a division of VMware
> 
>         _______________________________________________
>         rabbitmq-discuss mailing list
>         rabbitmq-discuss at lists.rabbitmq.com
>         https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss



More information about the rabbitmq-discuss mailing list