Author |
Message
|
iamaung |
Posted: Tue Jul 27, 2010 11:22 am Post subject: Message mismatch between Request Queue and Response Queue |
|
|
Newbie
Joined: 27 Jul 2010 Posts: 6
|
We are having very strange problem. Our request message id and the response message from response queue are not the same and all the messages are mismatch. Can anyone help please?
Here is the code we are using. Did we do something wrong?
MQConnectionFactory qconFactory = null;
MQConnection connection = null;
MQSession mqsession = null;
MQQueueSender sender = null;
MQQueue queue = null;
TextMessage msg = null;
MQQueueReceiver qReceiver = null;
MQQueue queue2 = null;
String replyMsg = new String();
TextMessage rplyMsg = null;
try{
qconFactory = (MQConnectionFactory) ctx.lookup("MQPROJECT.PRI.MQCF");
System.out.println("MQConnectionFactory OK.");
writeLogFile("MQConnectionFactory OK.");
} catch (NamingException ne){
System.out.println("MQConnectionFactory Err : "+ne.getMessage());
writeLogFile("MQConnectionFactory Err : "+ne.getMessage());
ne.printStackTrace();
return;
}
try{
connection = (MQConnection) qconFactory.createConnection();
System.out.println("MQConnection OK.");
writeLogFile("MQConnection OK.");
}catch (JMSException jmse) {
System.out.println("MQConnection Err : "+jmse.getMessage());
writeLogFile("MQConnection Err : "+jmse.getMessage());
jmse.printStackTrace(System.err);
return;
}
try{
mqsession = (MQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
System.out.println("MQSession OK.");
writeLogFile("MQSession OK.");
}catch (JMSException jmse) {
System.out.println("MQSession Err : "+jmse.getMessage());
writeLogFile("MQSession Err : "+jmse.getMessage());
jmse.printStackTrace(System.err);
return;
}
try {
queue = (MQQueue) ctx.lookup("MQREQUEST.ELK.ABC.DEF11");//Request Queue
queue.setTargetClient(1);
//Set TargetClient will assign current MQ request as JMS Queue Message
System.out.println("MQQueue OK.");
writeLogFile("MQQueue OK.");
}catch (NamingException ne) {
System.out.println("MQQueue Err : "+ne.getMessage());
writeLogFile("MQQueue Err : "+ne.getMessage());
ne.printStackTrace(System.err);
return;
}
try {
queue2 = (MQQueue) ctx.lookup("MQREPLY.ELK.ABC.XYZ11");//Reply Queue
System.out.println("MQQueue2 OK.");
writeLogFile("MQQueue2 OK.");
}catch (NamingException ne) {
System.out.println("MQQueue2 Err : "+ne.getMessage());
writeLogFile("MQQueue2 Err : "+ne.getMessage());
ne.printStackTrace(System.err);
return;
}
try {
msg = mqsession.createTextMessage();
System.out.println("CreateMessage OK.");
writeLogFile("CreateMessage OK.");
}catch (JMSException jmse) {
System.out.println("createTextMessage Err : "+jmse.getMessage());
writeLogFile("createTextMessage Err : "+jmse.getMessage());
jmse.printStackTrace(System.err);
return;
}
try {
sender = (MQQueueSender) mqsession.createProducer(queue);
System.out.println("MQQueueSender OK.");
writeLogFile("MQQueueSender OK.");
}catch (JMSException jmse) {
System.out.println("MQQueueSender Err : "+jmse.getMessage());
writeLogFile("MQQueueSender Err : "+jmse.getMessage());
jmse.printStackTrace(System.err);
return;
}
try {
connection.start();
System.out.println("Connection Start OK.");
writeLogFile("Connection Start OK.");
}catch (JMSException jmse) {
System.out.println("ConnectionStart Err : "+jmse.getMessage());
writeLogFile("ConnectionStart Err : "+jmse.getMessage());
jmse.printStackTrace(System.err);
return;
}
try {
msg.setJMSExpiration(2000);
msg.setJMSReplyTo(queue2);
msg.setText(strTxt);
sender.send(msg);
System.out.println("Message Send OK.");
writeLogFile("Message Send OK.");
}catch (Exception e) {
System.out.println("ConnectNSend Err : "+e.getMessage());
writeLogFile("ConnectNSend Err : "+e.getMessage());
e.printStackTrace(System.err);
return;
}
try {
sender.close();
System.out.println("SenderClose OK.");
writeLogFile("SenderClose OK.");
}catch (Exception e) {
System.out.println("MessageSenderClear Err : "+e.getMessage());
writeLogFile("MessageSenderClear Err : "+e.getMessage());
e.printStackTrace(System.err);
return;
}
//==================
try {
qReceiver = (MQQueueReceiver) mqsession.createConsumer(queue2);
System.out.println("MQQueueReceiver OK.");
writeLogFile("MQQueueReceiver OK.");
}catch (JMSException jmse) {
System.out.println("MQQueueReceiver Err : "+jmse.getMessage());
writeLogFile("MQQueueReceiver Err : "+jmse.getMessage());
jmse.printStackTrace(System.err);
return;
}
try {
rplyMsg = (TextMessage)qReceiver.receive(20000);
//msg is sending message and rplyMsg is to receive
rplyMsg.setJMSCorrelationID(msg.getJMSCorrelationID());
replyMsg = rplyMsg.getText();
System.out.println("MessageReceive OK.");
System.out.println("MsgReceive : "+replyMsg);
writeLogFile("MsgReceive : "+replyMsg);
}catch(Exception e) {
System.out.println("ReceiveMessage Err : "+e.getMessage());
writeLogFile("ReceiveMessage Err : "+e.getMessage());
e.printStackTrace(System.err);
return;
}
try {
qReceiver.close();
mqsession.close();
connection.close();
System.out.println("SenderClose OK.");
writeLogFile("SenderClose OK.");
}catch (Exception e) {
System.out.println("MessageSenderClear Err : "+e.getMessage());
writeLogFile("MessageSenderClear Err : "+e.getMessage());
e.printStackTrace(System.err);
return; |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jul 27, 2010 1:06 pm Post subject: Re: Message mismatch between Request Queue and Response Queu |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
The send method of the JMSProducer always creates a new messagId. So only use get by MessageId when you are absolutely certain. The pattern is response.getJMSCorrelId should match request.getJMSMessageId (after the send method).
Also you are setting the response message CorrelId to the request message CorrelId but the request message CorrelId was never set...
Quote: |
rplyMsg.setJMSCorrelationID(msg.getJMSCorrelationID()); |
Also you are confusing replymsg and request msg:
Quote: |
rplyMsg = (TextMessage)qReceiver.receive(20000);
//msg is sending message and rplyMsg is to receive
rplyMsg.setJMSCorrelationID(msg.getJMSCorrelationID());
replyMsg = rplyMsg.getText(); |
My suggestion sun JMS Tutorial
and come back when you understand more about JMS and request reply pattern.
Sorry Jeff you posted your reply before I was done editing mine...
 _________________ MQ & Broker admin
Last edited by fjb_saper on Tue Jul 27, 2010 2:08 pm; edited 1 time in total |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jul 27, 2010 1:43 pm Post subject: Re: Message mismatch between Request Queue and Response Queu |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
fjb_saper wrote: |
The send method of the JMSProducer always creates a new messagId. So only use get by MessageId when you are absolutely certain. The pattern is response.getJMSCorrelId should match request.getJMSMessageId (after the send method).  |
I'm not sure you've read through the code posted.
I'm also not sure what's wrong, per se.  |
|
Back to top |
|
 |
iamaung |
Posted: Tue Jul 27, 2010 7:48 pm Post subject: |
|
|
Newbie
Joined: 27 Jul 2010 Posts: 6
|
Thanks for the replies. This problem only happens when the MQ Reply Queue was down for several minute and the Request Queue got pile up with the request messages.
Is there anyway we can do from the coding side?
Is it MQ configuration issue?
Thank you so much! |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jul 28, 2010 11:12 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
iamaung wrote: |
Thanks for the replies. This problem only happens when the MQ Reply Queue was down for several minute and the Request Queue got pile up with the request messages.
Is there anyway we can do from the coding side?
Is it MQ configuration issue?
Thank you so much! |
Well I would expect that to happen. If you do not pick up your reply by correlationId... or if your correlationId is not set...
Again your code had several problems. Check a good JMSTutorial (Sun) and the samples for request / reply. You have java base and JMS samples for this pattern.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
iamaung |
Posted: Thu Jul 29, 2010 2:35 am Post subject: |
|
|
Newbie
Joined: 27 Jul 2010 Posts: 6
|
Thank you for your help so far.
Things are stable now. However, I am still get some mismatch if I am sending 1000 of messages from 4-5 computers at the same time.
What did I do wrong with this code?
Anything else I should add?
Code: |
QueueConnectionFactory qFactory=null;
QueueConnection qConnection=null;
QueueSession qSession=null;
QueueSender qSender=null;
QueueReceiver qReceiver=null;
Queue qQueue1=null;
Queue qQueue2=null;
TextMessage outgoingMsg = null;
Message incomingMsg = null;
String resXml ="";// new String();
try {
reqXml=getReqXML(cardCIFNo);
writeLogFile("Message to ICH :: " + reqXml);
ht.put("req","Message to ICH :: " + reqXml);
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "D:/jms_binding");
ctx = new InitialContext(env);
writeLogFile("InitialContext OK.");
qFactory = (QueueConnectionFactory) ctx.lookup("XYZ");
writeLogFile("MQConnectionFactory OK.");
qConnection = (QueueConnection) qFactory.createQueueConnection();
writeLogFile("MQConnection OK.");
qSession=qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
writeLogFile("MQSession OK.");
//QUEUE 1
qQueue1 = (Queue) ctx.lookup("ABC.XYZ1");//Request Queue
((MQQueue)qQueue1).setTargetClient(1);
writeLogFile("MQQueue1 OK.");
//QUEUE 2
qQueue2 = (Queue) ctx.lookup("XYZ.ABC1");//Reply Queue
writeLogFile("MQQueue2 OK.");
outgoingMsg= qSession.createTextMessage();
// outMsg.setIntProperty(JMS )
writeLogFile("CreateMessage OK.");
qSender = (QueueSender) qSession.createSender(qQueue1);
qSender.setTimeToLive(10000);
writeLogFile("MQQueueSender OK.");
qConnection.start();
writeLogFile("Connection Start OK.");
outgoingMsg.setJMSReplyTo(qQueue2);
outgoingMsg.setText(reqXml);
//outgoingMsg.setin
outgoingMsg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
System.out.println("%%%%% msg.getJMSMessageID() BEFORE SENDING : " + outgoingMsg.getJMSMessageID());
qSender.send(outgoingMsg);
writeLogFile("Message Send OK.");
System.out.println("%%%%% msg.getJMSMessageID() SENT : " + outgoingMsg.getJMSMessageID());
qSender.close();
writeLogFile("SenderClose OK.");
String myFilter="JMSCorrelationID = '" + outgoingMsg.getJMSMessageID() + "'";
System.out.println(" myFilter : " + myFilter);
qReceiver = (QueueReceiver) qSession.createReceiver(qQueue2);
writeLogFile("MQQueueReceiver OK.");
incomingMsg = qReceiver.receive(10000);
System.out.println("msg.getJMSMessageID() : " + outgoingMsg.getJMSMessageID());
if(incomingMsg==null){
System.out.println(" Reply TextMessage is NULL");
}else{
if(incomingMsg instanceof TextMessage){
resXml=((TextMessage) incomingMsg).getText();
}
}
writeLogFile("MessageReceive OK.");
writeLogFile("Message from ICH :: "+resXml);
ht.put("res","Message from ICH :: "+resXml);
qReceiver.close();
qSession.close();
qConnection.close();
writeLogFile("SenderClose OK.");
} catch (Exception e) {
e.printStackTrace();
}finally
{
try{
System.out.println(" Clear/Close started..");
ctx.close();
qConnection.close();
qSender.close();
ctx=null;
qFactory = null;
qConnection = null;
qSession = null;
qSender = null;
qQueue1 = null;
outgoingMsg = null;
incomingMsg=null;
qReceiver = null;
qQueue2 = null;
System.out.println(" Clear/Close ended..");
}catch(Exception ex){
ex.printStackTrace();
}
} |
|
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jul 29, 2010 2:40 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Where do you make use of the filter you built? |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Jul 29, 2010 2:58 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Quote: |
outgoingMsg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); |
I believe this gets overriden by the Destination properties.
Also make sure that you have AS Defined by application on the destination properties in JNDI.
Quote: |
String myFilter="JMSCorrelationID = '" + outgoingMsg.getJMSMessageID() + "'";
qReceiver = (QueueReceiver) qSession.createReceiver(qQueue2); |
Multiple trouble here.
- You should be using the filter in the receiver.
- Also where is the part that reads the message off the request queue and puts the response to the reply to queue? What exactly are you trying to do?
Your sample is different from the request / reply sample... did you work through the JMS tutorial and understand the pattern?
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
iamaung |
Posted: Thu Jul 29, 2010 8:49 am Post subject: |
|
|
Newbie
Joined: 27 Jul 2010 Posts: 6
|
Multiple trouble here.
a) You should be using the filter in the receiver.
Question: Sorry. How do I do that?
b) Also where is the part that reads the message off the request queue and puts the response to the reply to queue? What exactly are you trying to do?
Your sample is different from the request / reply sample... did you work through the JMS tutorial and understand the pattern?
Answer: I am sending a request to requestQueue. There is another application from someone else reading my request and placing back the response in replyQueue. I suppose to read the response from replyQueue.
So, therefore, I will send my request into requestQueue and read the reply from responseQueue. |
|
Back to top |
|
 |
iamaung |
Posted: Thu Jul 29, 2010 8:55 am Post subject: |
|
|
Newbie
Joined: 27 Jul 2010 Posts: 6
|
mqjeff wrote: |
Where do you make use of the filter you built? |
Sorry Jeff, how can I use it? Any pointer would be very helpful. Any URL to the sample code? |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Jul 29, 2010 12:26 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Sample code should be in your <MQInstallPath>/samp/java/jms  _________________ MQ & Broker admin |
|
Back to top |
|
 |
iamaung |
Posted: Fri Jul 30, 2010 11:44 pm Post subject: |
|
|
Newbie
Joined: 27 Jul 2010 Posts: 6
|
Problem solved. Thank you guys! |
|
Back to top |
|
 |
|