Get queues depth from java code

2020-07-24 06:13发布

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

标签: java jms ibm-mq
3条回答
Fickle 薄情
2楼-- · 2020-07-24 06:53

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);    
        }
查看更多
萌系小妹纸
3楼-- · 2020-07-24 06:55

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.

查看更多
狗以群分
4楼-- · 2020-07-24 06:57

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();
}
查看更多
登录 后发表回答