3

Can anyone help in doing the code in java of getting the depth of the queues. We are having 4 queues in IBM WebSphere MQ and inside them there are messages.

I want to write a jsp to read the queue names and their depth while running the report. How do I do that? Can anyone help in getting the full solution because I don't know what to do

1

3 Answers 3

4

I doens't think there is a way to retrieve the queue depth using JMS. You can however use MQ Series specific Java API to retrieve this information. Here is the sample code. Pay attention to int openOptions = MQC.MQOO_INQUIRE;

Here is the reference guide

int depth = 0;
MQQueueManager qMgr; // define a queue manager object
String mqHost = "";
String mqPort = "";
String mqChannel = "";
String mqQMgr = "";
String mqQueue = "";
try {
    // Set up MQSeries environment
   MQEnvironment.hostname = mqHost;
   MQEnvironment.port = Integer.valueOf(mqPort).intValue();
   MQEnvironment.channel = mqChannel;
   MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
   MQC.TRANSPORT_MQSERIES);
   qMgr = new MQQueueManager(mqQMgr);
   int openOptions = MQC.MQOO_INQUIRE;
   MQQueue destQueue = qMgr.accessQueue(mqQueue, openOptions);
   depth = destQueue.getCurrentDepth();
   destQueue.close();
   qMgr.disconnect();
} catch (Exception err) {
   err.printStackTrace();
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Pangea. Do I have to configure the queue configurations and save your code as .java and run it? or should I do something else?
@user1080320 download the library for the MQ Java api, put it in the classpath and run this code. Most probably the Queue might allow INQUIRY access but sometimes I believe this might be disabled on production queues or restricted only few admin users. Also, Upvote and accept the answer if this helped you.
Pangea, your topic is very helpful but where I can get the MQ Java Api and what is it? in which classpath?
@user1080320 follow this documentation and post on their forums to find where to download from publib.boulder.ibm.com/infocenter/wmqv6/v6r0/…
0

If you install the WMQ client from the IBM download (as opposed to just grabbing the class libs from the QMgr installation) you get sample code. Among the samples provided are several that list queue names, inquire on object properties and create objects. In a default installation on Win 7 these can be found at C:\Program Files (x86)\IBM\WebSphere MQ\tools\pcf\samples.

Download the WMQ client libraries here:

You are STRONGLY encouraged to use the latest WMQ client for any new development. It will work for all prior versions of WMQ at whatever level of functionality is provided by the target QMgr. Please see the Compatibility & Interop statement in the Infocenter. You can find the Infocenter for the WMQ version of server or client that you are using from the WMQ Library landing page.

Comments

0

A few of these functions are depreciated in IIB, so am pasting the updated code. It works :)

Enjoy

Getting MQ Queue Depth From Java:

try {
        int depth = 0;
        MQQueueManager qMgr; // define a queue manager object
        String mqHost = "";
        String mqPort = "";
        String mqChannel = "";
        String mqQMgr = "";
        String mqQueue = "";
        try {
            // Set up MQSeries environment
           MQEnvironment.hostname = mqHost;
           MQEnvironment.port = Integer.valueOf(mqPort).intValue();
           MQEnvironment.channel = mqChannel;
           //MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES);
           qMgr = new MQQueueManager(mqQMgr);
           //int openOptions = 1;//MQC.MQOO_INQUIRE;



           int openOptions = CMQC.MQOO_INQUIRE + CMQC.MQOO_FAIL_IF_QUIESCING + CMQC.MQOO_INPUT_SHARED;


           MQQueue destQueue = qMgr.accessQueue(mqQueue, openOptions);
           depth = destQueue.getCurrentDepth();
           destQueue.close();
           qMgr.disconnect();


            MbMessage outMessage = new MbMessage();
            outAssembly = new MbMessageAssembly(inAssembly, outMessage);
            MbElement root = outMessage.getRootElement();
            MbElement outXmlRoot =  root.createElementAsLastChild(MbXMLNSC.PARSER_NAME);
            MbElement Appointment = outXmlRoot.createElementAsLastChild(MbElement.TYPE_NAME, "RootElementXMLName", null);
            Appointment.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Q_DepthFromServer", depth);        
            out.propagate(outAssembly);    
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.