I am trying to fetch Current Depth, Last Puttime & last get time using java from IBM Mq's to monitor queue performance. I was able to fetch LPUTTIME & current depth using below code. I am using MQMESSAGE browse api. But i am having hard time to fetch the LGETTIME (Last message get time)- last message that was processed out of queue. Because MQMESSAGE browse has nothing like Last get time. Any help regarding this ????
public int depthOf(String queueName) throws MQException {
MQQueue queue = qmgr.accessQueue(queueName, mqOpnOpt, null, null, null);
int qDpth = queue.getCurrentDepth();
queue.close();
//qmgr.disconnect();
System.out.println("Current Depth of "+ queueName + " is " + qDpth);
return qDpth;
}
@SuppressWarnings("unchecked")
private MQQueueManager createQueueManager() throws MQException {
MQEnvironment.channel = channel;
MQEnvironment.port = port;
MQEnvironment.hostname = host;
MQEnvironment.properties.put(CMQC.TRANSPORT_PROPERTY,
CMQC.TRANSPORT_MQSERIES);
return new MQQueueManager(manager);
}
/**
* Returns 1st message put time when it is put in to Queue and not consumed.
*
* @return
* @throws MQException
*/
public int queueMsgAge() throws MQException {
MQQueue queue = null;
MQMessage message = new MQMessage();
queue = qmgr.accessQueue(queueName, MQC.MQOO_BROWSE
| MQC.MQOO_FAIL_IF_QUIESCING);
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_NO_WAIT;
queue.get(message, gmo);
GregorianCalendar cal = message.putDateTime;
long ageInMillis = new java.util.Date().getTime()
- cal.getTime().getTime();
int ageInSeconds = (int) ageInMillis / 1000;
System.out.println("Put Date & Time: "+ cal.getTime()
+ " Age of Msg in seconds: " + ageInSeconds + " Queue Name "
+ queueName);
_log.info("Put Date & Time: " + cal.getTime() + " Age of Msg in seconds: "
+ ageInSeconds + " Queue Name " + queueName);
return ageInSeconds;
}
First read JoshMc & Morag's comments above.
Second, you should play around with runmqsc issuing both types of Queue Status commands. i.e. HANDLE vs QUEUE. Note: You are interested in the values related to Queue Status Type(QUEUE).
i.e. runmqsc command:
Third, don't use the MQEnvironment class as it is not thread safe. Put the connection information in a Hashtable and pass the Hashtable to the MQQueueManager class.
As mentioned in the comments above, you cannot retrieve that information via a regular MQ program. You need to write a MQ Java program that issues a PCF command to the queue manager's command server.
When creating a PCF request message, the parameters MUST added in a particular order. It is a bit of a pain but you just get use to it.
Here is a simple MQ Java program that will issue a PCF "Inquire Queue Status" command, get the PCF response messages, loop through the PCF responses and output the information.