Tuesday, February 24, 2009

JMS API Lacks Depth.

The JMS API still does not cater for a simple method to obtain the number of messages on a queue. Currently you have to jump through the following hoops to get the queue depth:
1) Create Connection
2) Create Session
3) Create QueueBrowser
4) getEnumeration
5) iterate through the enumeration while incrementing a count.

On some JMS implementations for large queue depths this approach has rapidly resulted in OutOfMemoryException, as the entire enumeration is loaded into memory.
So inevitably, the developer ends up dropping into proprietary code thereby losing portability and increasing vendor lock-in. OK this could be tempered by creating a factory pattern implementation ... but why, multiple times across many development organisations.

Many JMS implementations have a native way of simply obtaining the queue depth along the lines of the following:
1) Create Connection
2) Create Session
3) getQueueDepth(Queue queue)

This doesn't involve loading all the messages into memory, and it is s common that it ought to be added to the standard JMS implementation.
I believe that this should return -1 if it is not supported else return the actual queue depth.
There could be another variation,
int javax.jms.Session.getQueueDepth(Queue queue, String messageSelector)

I'm not sure whether this should be applicable to topics, as depth is relative to the consumer, perhaps the subscriber name could be passed in to a similar method.

Its coming up to 7 years since the release of JMS-1.1, surely this feature alone is worth releasing JMS-1.2.

No comments: