views:

469

answers:

1

I have an IBM MQ series queue (running on Windows) containing many items of varying priority.

I currently get a total depth count using mqQueue.CurrentDepth but I'd like to get a count of the number of items of each priority level within the queue.

Any idea how to achieve this?

+1  A: 

You could use a JMS QueueBrowser to browse the messages in the queue and build up totals for each priority levels.

QueueBrowser browser = session.createBrowser(someQueue);
for (Enumeration iter = browser.getEnumeration(); iter.hasMoreElements()) {
  Message message = (Message) iter.nextElement();
  int priority = message.getJMSPriority();
  // update counters...
}
James Strachan
Keeping in mind that the numbers achieved are just approximations. In the time it takes to count the messages, the contents of the queue may have changed considerably. the count of higher priority messages will tend to have a larger error rate than that of lower priority messages. The rate of enqueue/dequeue will also affect the reliability of the count with error rates increasing with activity. So this code gets the job done but the underlying requirement is questionable on its face.
T.Rob