开发者

How to check whether have message in the queue

I am using IBM Websphere MQ. I have the queue manager and queue name. Now, I want to check开发者_开发百科 whether the queue has any messages in it?

I did not work on this before. Pleas help

Please let me know if you need further information!

Thanks


The below code is .NET / amqmdnet - but you might try and convert this in the meantime until a Java dev sees your post.

To see if there is a message on the queue, without actually taking it off the queue, use MQC.MQOO_BROWSE on the Queue and IBM.WMQ.MQC.MQGMO_BROWSE_FIRST as the option You'll get MQRC_NO_MSG_AVAILABLE if the queue is empty.

MQMessage queueMessage = new MQMessage();

MQQueueManager queueManager = new MQQueueManager(qmName, channelName, connName);
MQQueuequeue = queueManager.AccessQueue(qName, 
    MQC.MQOO_BROWSE + MQC.MQOO_FAIL_IF_QUIESCING);

MQGetMessageOptions opt = new MQGetMessageOptions();
opt.Options = IBM.WMQ.MQC.MQGMO_BROWSE_FIRST;
queueMessage.CorrelationId = IBM.WMQ.MQC.MQMI_NONE;
queueMessage.MessageId = IBM.WMQ.MQC.MQMI_NONE;
queue.Get(queueMessage, opt);
String sMessage = queueMessage.ReadString(queueMessage.DataLength);

To peek the next message use IBM.WMQ.MQC.MQGMO_BROWSE_NEXT;

To actually read the message OFF the queue, use MQC.MQOO_INPUT_SHARED on the AccessQueue.


The answer didn't show how to check for MQRC_NO_MSG_AVAILABLE. Here is my solution. If there are better ones please let me know.

try
{
    queue.Get(queueMessage, opt);
    String sMessage = queueMessage.ReadString(queueMessage.DataLength);
}
catch (MQException err)
{
    if (err.ReasonCode.CompareTo(MQC.MQRC_NO_MSG_AVAILABLE) == 0)
        return true;
}


For Windows machine It depends on where your queue manager is.

You could use MQUtilities - ih03 pack - which has rfhUtil.exe (Local Qm) and rfhUtilC.exe (for remote qm)

For Local QM , it is straight forward you need to place appropriate values and hit browse, it will show you Queue Depth.

For Remote QM, Place /TCP/(PortNo) for queue manager name and queue for queue name. Hit browse and you will get to know the queue depth.

For Unix/Ubuntu/Linux versions - There is a product called MQVisualEdit which is similar to this one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜