1

How can I use the IBM MQ Java APIs to query for the maximum queue depth attribute of a queue?

2 Answers 2

2

You can use MQ PCF to retrieve attribute values of a queue.

i.e.

request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q);

/**
 * You can explicitly set a queue name like "TEST.Q1" or
 * use a wild card like "TEST.*"
 */
request.addParameter(CMQC.MQCA_Q_NAME, "*");

// Add parameter to request only local queues
request.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);

// Add parameter to request all of the attributes of the queue
request.addParameter(CMQCFC.MQIACF_Q_ATTRS, new int [] { CMQC.MQCA_Q_NAME,
                                                         CMQC.MQIA_CURRENT_Q_DEPTH,
                                                         CMQC.MQIA_MAX_Q_DEPTH
                                                       });

responses = agent.send(request);

for (int i = 0; i < responses.length; i++)
{
   if ( ((responses[i]).getCompCode() == CMQC.MQCC_OK) &&
        ((responses[i]).getParameterValue(CMQC.MQCA_Q_NAME) != null) )
   {
      String name = responses[i].getStringParameterValue(CMQC.MQCA_Q_NAME);
      if (name != null)
         name = name.trim();

      int depth = responses[i].getIntParameterValue(CMQC.MQIA_CURRENT_Q_DEPTH);
      int maxDepth = responses[i].getIntParameterValue(CMQC.MQIA_MAX_Q_DEPTH);
   }
}

I thought I posted MQListQueueAttributes01.java to StackOverflow but I cannot find it. It is on my blog.

It is a complete and fully functioning Java/MQ/PCF program to retrieve all attributes values of a queue. If you click on "PCF" category on my blog, you will find a variety of complete sample Java/MQ/PCF programs.

Sign up to request clarification or add additional context in comments.

Comments

1

One way of doing it is by using the inquire method on the MQQueue object:

import com.ibm.mq.MQException;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;

import static com.ibm.mq.constants.CMQC.MQIA_MAX_Q_DEPTH;
import static com.ibm.mq.constants.CMQC.MQOO_INQUIRE;

public class SampleJavaCode {
    public static void main(String[] args) throws MQException {
        MQQueueManager mqQueueManager = ...;
        MQQueue mqQueue = mqQueueManager.accessQueue("ORDER", MQOO_INQUIRE);
        int[] selectors = new int[]{MQIA_MAX_Q_DEPTH};
        int[] intAttrs = new int[1];
        byte[] charAttrs = new byte[0];
        mqQueue.inquire(selectors, intAttrs, charAttrs);
        System.out.println("Max Queue depth = " + intAttrs[0]);
    }
}

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.