Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get message count on a Weblogic  queue via JMX

Posted on 2008-06-26
4
Medium Priority
?
4,599 Views
Last Modified: 2013-12-10
Hello,
    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

Adil
0
Comment
Question by:AdilK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 21881913
0
 

Author Comment

by:AdilK
ID: 21883166
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.
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 300 total points
ID: 21883638
You could combine them both by implementing your own code to do this, by just using the standard JMS and JMX APIs

http://java.sun.com/products/jms/tutorial/
http://java.sun.com/j2se/1.5.0/docs/guide/jmx/tutorial/tutorialTOC.html

Alternatively you can look here for some sampel code:

http://forums.bea.com/thread.jspa?threadID=400003747

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

Accepted Solution

by:
AdilK earned 0 total points
ID: 21884607
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();
		env.setSecurityPrincipal("weblogic");
		env.setSecurityCredentials("weblogic");
		env.setProviderUrl("t3://localhost:7001");
		try {
			ic = (javax.naming.Context) env.getInitialContext();
			
			factory = (QueueConnectionFactory) ic
					.lookup("javax.jms.QueueConnectionFactory");
			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);			
			qcon.start();
 
			java.util.Enumeration pendingMessages = queueBrowser.getEnumeration();
			int count = 0;
			while (pendingMessages.hasMoreElements()) {
			   count++;
			   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) {
			e.printStackTrace();
		}
		catch (JMSException e) {
			e.printStackTrace();
		}
	}

Open in new window

0

Featured Post

Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
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…
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.

660 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