How to get message count on a Weblogic  queue via JMX

Posted on 2008-06-26
Last Modified: 2013-12-10
    I am trying to create a client that will remotely be able to get the message count from a JMS queue via JXM ? Since I am new to the entire JMX thing so I have been reading a lot of articles and forums about this and so far from what i understand is that JMX api include a QueueBrowser that will allow one to inspect the queue. My question is how do I get the QueueBrowser ? I am using Weblogic so if there are specific weblogic APIs I can use to ease my task please let me know.

Thanks in advance

Question by:AdilK
  • 2
  • 2
LVL 35

Expert Comment

Comment Utility

Author Comment

Comment Utility
Yes I have. These are for version prior to WL 10. Apparently there were weblogic specific classes one could use to query the queues and stuff but they removed it in version 9 I believe and suggested to go regular JMX route. Thats the route I do not know how to take. My problem is that I need to query the server for Queues and for each queue see how many messages are present i.e get a message count. I know there are classes such as QueueBrowser and QueueConnectionFactory but I dont know how to instantiate them. If any one can give me specific examples how to instantiate QueueConnectionFactory using javax.naming.Context from a WL server with code it would be great.
LVL 35

Assisted Solution

girionis earned 75 total points
Comment Utility
You could combine them both by implementing your own code to do this, by just using the standard JMS and JMX APIs

Alternatively you can look here for some sampel code:

although the user says that it's not quite working.

Accepted Solution

AdilK earned 0 total points
Comment Utility
Thanks for the help . I resolved it and following is my solution for anyone who comes after me tryingto do the same thing.

public void getQueueData() {

		QueueConnectionFactory factory = null;

		Queue queue = null;

		javax.jms.QueueSession qsession = null;

		javax.jms.QueueConnection qcon = null;

		javax.naming.Context ic = null;

		Environment env = new Environment();




		try {

			ic = (javax.naming.Context) env.getInitialContext();


			factory = (QueueConnectionFactory) ic


			queue = (Queue) ic.lookup(YOUR_QUEUE_NAME);

			qcon = factory.createQueueConnection();

			/* creating a queue sessionobject */


			qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

			QueueBrowser queueBrowser = qsession.createBrowser(queue);			


			java.util.Enumeration pendingMessages = queueBrowser.getEnumeration();

			int count = 0;

			while (pendingMessages.hasMoreElements()) {


			   javax.jms.Message message = (Message)pendingMessages.nextElement();

			   Date messageDate = new Date(message.getJMSTimestamp());

			   System.out.println("Message Date is " + messageDate);


			System.out.println("Queue messages " + count);


		} catch (NamingException e) {



		catch (JMSException e) {




Open in new window


Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
NotAlone Challenge 20 70
Enhanced For loop vs ForEach Loop 4 54
strDist challenge 35 84
What is the latest versions eclipse neon 2 113
Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now