Reputation: 1530
How can I use the IBM MQ Java APIs to query for the maximum queue depth attribute of a queue?
Upvotes: 1
Views: 855
Reputation: 7476
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.
Upvotes: 2
Reputation: 1530
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]);
}
}
Upvotes: 1