activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: Get Queue message count in 4.0
Date Sat, 06 May 2006 07:08:32 GMT
On 5/5/06, Adrian Tarau <> wrote:
> I just did you you told me :

Have you tried printing out what is in the destinationMap?

The keys are ActiveMQDestination objects - since topics and queues
both can have identical names, using a String key could cause clashes;
so looking things up by String is not gonna work - use the
ActiveMQDestination (e.g. the ActiveMQQueue object) as the key and it
should work. Or worse case, iterate through the Map and compare the
String value of the key etc.

> On the other hand, this piece of code seems to work fine :
> private int getQueueSize(Queue queue) throws JMSException {
>         MessageConsumer consumer = session.createConsumer(queue);
>         try {
>             if (consumer instanceof ActiveMQMessageConsumer) {
>                 return ((ActiveMQMessageConsumer)
> consumer).getMessageSize();
>             }
>         } finally {
>             consumer.close();
>         }
>         int count = 0;
>         QueueBrowser browser = session.createBrowser(queue);
>         Enumeration enumeration = browser.getEnumeration();
>         while (enumeration.hasMoreElements()) {
>             enumeration.nextElement();
>             count++;
>         }
>         return count;
>     }

Sure - the thing is if you had 1 million messages on a queue; asking
for the size that way could take a very long time since basically you
have to connect to the broker, set up a browser, send every message to
the client (which will involve much querying of the database and tons
of data being sent) just to find out that there is 1 million messages
on the queue.

The broker already maintains a counter for this, so its a trivial
operation to just ask the broker.

Seriously, its probably way simple to just use JMX if you're having
trouble with this Map. Just point JConsole at the broker and you can
see the stats....



View raw message