Ruslan
Ruslan

Reputation: 319

MQMessage read or delete

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);
}

Upvotes: 1

Views: 2346

Answers (1)

T.Rob
T.Rob

Reputation: 31832

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 can GET 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 to GET using the MsgID that you obtained from the browse. Simply call the other thread and pass it the MsgID. The simplest way is to use one thread and the browse cursor.

Upvotes: 3

Related Questions