lundi 23 février 2015

Unable to retrieve message from MQ Queue



I am trying to retrieve message from MQ Queue. Below is the code I am using:



//Fetching Queue details
MQEnvironment.hostname=getMqCall().getMqHost();
MQEnvironment.channel=getMqCall().getMqChannel();
MQEnvironment.port=getMqCall().getMqPort();
MQQueueManager qMgr= new MQQueueManager(getMqCall().getMqQueManager());
MQQueue outputQueue = qMgr.accessQueue(getMqCall().getRespQueue(), MQC.MQOO_INQUIRE | MQC.MQOO_BROWSE | MQC.MQOO_INPUT_AS_Q_DEF);

//Checking for messages in queue
int i=outputQueue.getCurrentDepth();
System.out.println("Number of messages in Assign promo queue:: "+i);

for(int j=0;j<i;j++){
MQMessage sampleResponse = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
outputQueue.get(sampleResponse, gmo);
String msgtext = sampleResponse.readStringOfCharLength(sampleResponse.getMessageLength());

System.out.println("Message read is: "+msgtext);
System.out.println("Response length: "+sampleResponse.getTotalMessageLength());

if(msgtext!=null){

// Some code

}else{

System.out.println("Message not read from response queue");

}

}

//Checking for messages in queue after processing
i=outputQueue.getCurrentDepth();
System.out.println("Number of messages in queue after processing :: "+i);

outputQueue.close();
qMgr.close();
qMgr.disconnect();


I get msgtext value as null, even though getCurrentDepth() shows me that values are present in the queue. Even the getTotalMessageLength() returns null value. Have verified that messages are present on that queue.


Earlier I was using readString() method in the place of readStringOfCharLength(). However, I was still not getting the response, so I checked with readStringOfCharLength() as readString() method is deprecated.


I have even tried with readLine() method, but still not able to retrieve the message.


Thanks in advance.


PS: I am running the above piece of code via a scheduler which runs every 15 mins.




Aucun commentaire:

Enregistrer un commentaire