V
Vadim
Hi,
I am writing an MQ client that should get messages from MQ Queue one
by one and then delete it in case of successful processing.
As documented in MQ Series Programming Guide a queue should be opened
for browsing and removing. For browsing an option
MQGMO_BROWSE_FIRST or MQGMO_BROWSE_NEXT should be used and for
deleting MQGMO_BROWSE_MSG_UNDER_CURSOR.
Browsing works fine for me but delete does not - all messages remain
in a queue.
Thanks
Following is a code fragment:
..................
try {
mQMgr = new MQQueueManager(remoteQManager);
int openInputOptions = MQC.MQOO_FAIL_IF_QUIESCING |
MQC.MQOO_INPUT_SHARED | MQC.MQOO_BROWSE;
outputQueue=mQMgr.accessQueue(remoteQueue, openInputOptions);
MQMessage retrievedMessage = new MQMessage();
MQGetMessageOptions gmo=new MQGetMessageOptions();
gmo.options=MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
gmo.matchOptions=MQC.MQMO_NONE;
gmo.waitInterval=10000;
while(true) {
if(c>0) { gmo.options = MQC.MQGMO_WAIT |
MQC.MQGMO_BROWSE_NEXT; }
outputQueue.get(retrievedMessage, gmo);
msg=retrievedMessage.readString(retrievedMessage.getMessageLength());
System.out.println("************************ message "+c+"
********************** " + retrievedMessage.persistence);
System.out.println("RETRIEVED MESSAGE: "+msg);
System.out.println("REMOVING
..................................");
gmo.options = MQC.MQGMO_WAIT |
MQC.MQGMO_BROWSE_MSG_UNDER_CURSOR;
outputQueue.get(retrievedMessage, gmo);
c++;
}
} catch (MQException mqe) {
if(mqe.reasonCode == mqe.MQRC_NO_MSG_AVAILABLE) {
System.out.println("NO MORE MESSAGES AVAILABLE, RETRIEVED
"+c);
return;
}
mqe.printStackTrace();
} catch (java.io.IOException ioe) {
ioe.printStackTrace(System.out);
return;
} finally {
try {
System.out.println("CLOSING A QUEUE & MANAGER");
if(outputQueue != null) { outputQueue.close(); }
if(mQMgr != null) { mQMgr.disconnect(); }
}
catch (MQException ex) {
ex.printStackTrace();
}
}
I am writing an MQ client that should get messages from MQ Queue one
by one and then delete it in case of successful processing.
As documented in MQ Series Programming Guide a queue should be opened
for browsing and removing. For browsing an option
MQGMO_BROWSE_FIRST or MQGMO_BROWSE_NEXT should be used and for
deleting MQGMO_BROWSE_MSG_UNDER_CURSOR.
Browsing works fine for me but delete does not - all messages remain
in a queue.
Thanks
Following is a code fragment:
..................
try {
mQMgr = new MQQueueManager(remoteQManager);
int openInputOptions = MQC.MQOO_FAIL_IF_QUIESCING |
MQC.MQOO_INPUT_SHARED | MQC.MQOO_BROWSE;
outputQueue=mQMgr.accessQueue(remoteQueue, openInputOptions);
MQMessage retrievedMessage = new MQMessage();
MQGetMessageOptions gmo=new MQGetMessageOptions();
gmo.options=MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
gmo.matchOptions=MQC.MQMO_NONE;
gmo.waitInterval=10000;
while(true) {
if(c>0) { gmo.options = MQC.MQGMO_WAIT |
MQC.MQGMO_BROWSE_NEXT; }
outputQueue.get(retrievedMessage, gmo);
msg=retrievedMessage.readString(retrievedMessage.getMessageLength());
System.out.println("************************ message "+c+"
********************** " + retrievedMessage.persistence);
System.out.println("RETRIEVED MESSAGE: "+msg);
System.out.println("REMOVING
..................................");
gmo.options = MQC.MQGMO_WAIT |
MQC.MQGMO_BROWSE_MSG_UNDER_CURSOR;
outputQueue.get(retrievedMessage, gmo);
c++;
}
} catch (MQException mqe) {
if(mqe.reasonCode == mqe.MQRC_NO_MSG_AVAILABLE) {
System.out.println("NO MORE MESSAGES AVAILABLE, RETRIEVED
"+c);
return;
}
mqe.printStackTrace();
} catch (java.io.IOException ioe) {
ioe.printStackTrace(System.out);
return;
} finally {
try {
System.out.println("CLOSING A QUEUE & MANAGER");
if(outputQueue != null) { outputQueue.close(); }
if(mQMgr != null) { mQMgr.disconnect(); }
}
catch (MQException ex) {
ex.printStackTrace();
}
}