activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adrian Tarau <...@daxtechnologies.com>
Subject Re: Get Queue message count in 4.0
Date Fri, 05 May 2006 15:50:45 GMT
I just did you you told me :

protected int getQueueCount(Queue queue) throws JMSException {
        try {
            Map destinationMap = 
brokerService.getBroker().getDestinationMap();
            org.apache.activemq.broker.region.Destination destination = 
(org.apache.activemq.broker.region.Destination) 
destinationMap.get(queue.getQueueName());
            if (destination != null) {
                return (int) destination.getQueueSize();
            }
        } catch (Exception e) {
            LOG.error("Cannot get queue " + queue.getQueueName() + " 
count", e);
        }
        return 0;
    }

and since the browser just started there was only 2 entries in the map, 
something probably related with ActiveMQ.
So my queue was not present in the map.

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

James Strachan wrote:
> On 5/5/06, Adrian Tarau <ady@daxtechnologies.com> wrote:
>   
>> Well I just compiled what you just told me, there are statistics. This
>> wouldn't help me.
>>     
>
> Huh? Look at all the methods on Destination...
>
> http://activemq.codehaus.org/maven/apidocs/org/apache/activemq/broker/region/Destination.html
>
> e.g. getQueueSize()
>
>
>   
>> What I need is, after the application starts to see how many messages
>> are in the persistence related with a queue name
>>     
>
> See above
>
>   
>> , so a plain SQL on the
>> messages table with a filter should give me what I want.
>>     
>
> No it won't as that is stale for long periods of time - since we write
> to the journal then only at checkpoint do we update the database; so
> the database is generally stale most of the time.
>
> --
>
> James
> -------
> http://radio.weblogs.com/0112098/
>   


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message