Wednesday, May 21, 2008

stcqueueviewer: Dinamically Monitoring JCAPS JMS Server Queues

Disclaimer: the below procedure is undocumented and not officially supported, so you are using this at your own risk only. Please contact Sun's JavaCAPS support or Professional Services for more

I recently had to dynamically monitor some JMS queues within JavaCAPS , especially my need was to count the number of messages in a given queue before posting additional messages, to avoid unnecessary queue flooding. JavaCAPS is fully JMX compliant, the embedded Sun Application Server is well-documented on that side but the SeeBeyond IQ Manager (default JavaCAPS' JMS server implementation) is lacking some info, so I decided to go for some hacking.
My colleague Paul pointed me in the right direction, he suggested to have a look at the com.stc.jms.stcqueueviewer.jar contained into
logicalhost\is\stcms\lib
This library is almost undocumented, so I had to reverse-engineer its classes by using the nice DJ tool. The most interesting file is called Server.java, the Server class contains what is necessary to fully monitor the SeeBeyond IQ manager from a Java program. Below an example:

package queuemonitor;

import com.stc.jms.queueviewer.*;

public class Main {

public static void main(String[] args) throws Exception {

Server sv = new Server();

sv.connect("localhost", 18007, "Administrator", "STC");

QueueStatistics queueStatistics = new QueueStatistics();

sv.getQueueStatistics(queueStatistics, "qStoreDocument");
System.out.println("MinSeqNo=" + queueStatistics.MinSeqNo);
System.out.println("MaxSeqNo=" + queueStatistics.MaxSeqNo);
System.out.println("MessageCount=" + queueStatistics.MessageCount);
sv.disconnect();
}
}

To compile and run this with Netbeans 6 you need to import some additional JAR files from the JavaCAPS Logicalhost logicalhost\is\stcms\lib folder:
  • com.stc.jms.stcjms.jar
  • com.stc.jms.stcqueueviewer.jar
  • jms.jar


By the way, if you have not tried the new Netbeans 6 yet, then shame on you!

If you want instead to do the same within a JavaCAPS JCD you need to execute the following steps:
1. create a new JCD
2. Import the com.stc.jms.stcqueueviewer.jar JAR file into repository
3. Import the above JAR into the JCD


4. Do something useful with the dynamic information you get


The above JCD example is pretty silly, just to show you something

That's it. There other useful methods into Server class, you can explore and discover other interesting things. Hopefully somewhere more queueviewer's documentation is available, so it won't be necessary to decompile the Java classes...

6 comments:

  1. Why did you shy away from stcmsctrlutil.exe? I've written some monitoring scripts in Perl and in java that talk to this command.

    ReplyDelete
  2. Because I don't want to launch an external process, everything needs to run within the same JCD thread.

    ReplyDelete
  3. Hi,
    I am trying to create a standalone application using swing to publish the message. But sv.connect()method its not connecting to the remote server,instead throwing time out exception. But when i am running the same code in any server its working fine. i am able to send message to any server on the network.
    But i dont want any server interactions.Any idea why its working?

    ReplyDelete
  4. Vinoth, what is your exception? I was running it from a stand-alone Java client without problems. Have you included all the necessary JAR files?

    ReplyDelete
  5. Ive imported the jar file.When i run the code that is provided , it throws an error.It is not recognising the server code.

    ReplyDelete
  6. Manjula, you provided a bit too few information to suggest any solution...

    ReplyDelete