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 <[EMAIL PROTECTED]> 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/