Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we reading multiple messages single time using java

 
ishmayel vemuru
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic