MQMessage 读取或删除
我们有 WebSphere MQ 服务器。 我编写了 Java 客户端实用程序,它可以读取所有消息(将它们留在队列中)或从队列中删除所有消息。 但是是否可以读取消息并且如果它包含某些字符串 - 删除它?
要读取我使用的队列消息(消息将保留在服务器队列上以供将来处理,因为实用程序仅用于测试):
MQQueue queue = queueManager.accessQueue(queueName, MQC.MQ00_BROWSE | MQC.MQ00_INPUT_SHARED);
MQGetMessageOptions options = new MQGetMessageOptions();
options.options = MQC.MQ00_BROWSE_FIRST | MQC.MQ00_INPUT_SHARED;
while(true) {
MQMessage msg = new MQMessage();
queue.get(msg, options);
if (msg.getTotalMeesageLength() == 0) {
break;
} else {
readMessage(msg);
}
we have WebSphere MQ server.
I have written Java client utility which can read all messages (leaving them in queue) or delete all from queue.
But is that possible to read message and if it contains certain string - delete it?
To read queue message i use (message will stay on server queue for future processing, coz utility only for testing):
MQQueue queue = queueManager.accessQueue(queueName, MQC.MQ00_BROWSE | MQC.MQ00_INPUT_SHARED);
MQGetMessageOptions options = new MQGetMessageOptions();
options.options = MQC.MQ00_BROWSE_FIRST | MQC.MQ00_INPUT_SHARED;
while(true) {
MQMessage msg = new MQMessage();
queue.get(msg, options);
if (msg.getTotalMeesageLength() == 0) {
break;
} else {
readMessage(msg);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上是一个相当普遍的要求。方法是浏览消息以查找要删除的消息。当您找到它时,使用破坏性的
GET
将其删除。您可以使用浏览光标GET
消息,如信息中心此处。您还可以使用一个单独的线程及其自己的队列句柄,通过从浏览中获取的MsgID
来进行GET
操作。只需调用另一个线程并向其传递MsgID
即可。最简单的方法是使用一个线程和浏览光标。This is actually a fairly common requirement. The methodology is to browse through the messages looking for the one you want to delete. When you find it, delete it with a destructive
GET
. You canGET
the message using the browse cursor as described in the Infocenter here. You can also use a separate thread with it's own queue handle toGET
using theMsgID
that you obtained from the browse. Simply call the other thread and pass it theMsgID
. The simplest way is to use one thread and the browse cursor.