ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » readi messages from queue

Post new topic  Reply to topic
 readi messages from queue « View previous topic :: View next topic » 
Author Message
dsmq
PostPosted: Thu Jul 07, 2005 10:48 am    Post subject: readi messages from queue Reply with quote

Acolyte

Joined: 20 Jun 2002
Posts: 59

Hi

I am trying to read messages from queue .but i am getting always only one message . its reading only one message at a time , instead of all messages

i am using following code



import com.ibm.mq.*;
import java.util.Hashtable;

public class GetMessage {

private String qManager = "JMSSVR"; // define name of queuemanager to connect to.
private MQQueueManager qMgr; // define a queue managerobject
boolean EOM = false;

public static void main(String args[]){
GetMessage msg = new GetMessage();
}
public GetMessage() {

try {

// Set up MQSeries environment
MQEnvironment.hostname = "abcd";
MQEnvironment.channel = "SYSTEM.DEF.SVRCONN";

//Create a connection to the queue manager
qMgr = new MQQueueManager(qManager);

// Set up the options on the queue we wish to open...
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF| MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQOO_OUTPUT;

// and the open options...
MQQueue queue = qMgr.accessQueue("TEST",
openOptions,
null,
null,
null);


MQMessage msg1 = new MQMessage();
msg1.writeUTF("Message with Message Id!");

// specify the message options...

MQPutMessageOptions pmo1 = new MQPutMessageOptions(); // same as MQPMO_DEFAULT
queue.put(msg1,pmo1);

//For message 2
MQMessage msg2 = new MQMessage();
// msg2.correlationId = msg1.messageId;
msg2.writeUTF("message with Correlation Id!");
MQPutMessageOptions pmo2 = new MQPutMessageOptions();
// put the message on the queue
queue.put(msg2,pmo2);

// get the message back again...
MQMessage getMessage = new MQMessage();
//retrievedMessage.messageId = msg2.messageId;

MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING;


do{
queue.get(getMessage, gmo);
String msgText = getMessage.readString(getMessage.getMessageLength());
System.out.println("The message is: " + msgText);

} while(!EOM);

queue.close(); // Close the queue...
qMgr.disconnect(); // Disconnect from the queue manager
} catch (MQException mqe) {
System.out.println("An MQSeries error occurred : Completion code " +
mqe.completionCode + " Reason code " + mqe.reasonCode);
if (mqe.reasonCode != 2033) {
System.out.println("MQ Error: " + mqe.getMessage());
}
if (mqe.reasonCode == 2033) {
System.out.println("All messages read.");
EOM = true;
}
} catch (java.io.IOException ex) {
System.out.println("An error occurred whilst writing to the message buffer: " + ex);
EOM = true;
}
}
}



pls let me know where i am going wrong
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Jul 07, 2005 1:40 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

It's your try catch block.
You are using writeutf it would be prudent to use readutf.
You can have imbricated try catch blocks.
There is no EOM marker. You will get an exception with error code 2033.

Enjoy
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » readi messages from queue
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.