aspose file tools
The moose likes Websphere and the fly likes Can we reading multiple messages single time using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Can we reading multiple messages single time using java" Watch "Can we reading multiple messages single time using java" New topic
Author

Can we reading multiple messages single time using java

ishmayel vemuru
Ranch Hand

Joined: Jun 13, 2007
Posts: 46
Hi All,
I am new to MQ API (IBM MQ 7.0), I hava a requirement to read multiple messages from queue and insert those multiple message into DB as a batch.
following code I am using with this I am able to read one by one message from queue.

private void read() throws MQException {
int openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INPUT_SHARED ;
MQQueue queue = _queueManager.accessQueue(inputQName, openOptions,
null, // default q manager
null, // no dynamic q name
null); // no alternate user id
int depth = queue.getCurrentDepth();
System.out.println("Current depth: " + depth + "\n");
if (depth == 0) {
return;
}
MQGetMessageOptions getOptions = new MQGetMessageOptions();
getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_CONVERT;
while(true){
MQMessage message = new MQMessage();
try {
queue.get(message, getOptions);
byte[] b = new byte[message.getMessageLength()];
System.out.println("Before RedFully");
message.readFully(b);
System.out.println("Messages from Queue:"+new String(b));
}
catch (IOException e) {
System.out.println("IOException during GET: " + e.getMessage());
break;
}
catch (MQException e) {
if (e.completionCode == 2 && e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) {
if (depth > 0)
System.out.println("All messages read.");
}
break;
}
}
queue.close();
_queueManager.commit();
_queueManager.disconnect();
}

Kindly advise me if there is any way to read the multiple message from queue at a time.
Thanks in advance for your time.

Regards,
Ishmayel
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can we reading multiple messages single time using java
 
It's not a secret anymore!