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 Installation/Configuration Support » How to get the messages with the proper MessageId

Post new topic  Reply to topic Goto page 1, 2  Next
 How to get the messages with the proper MessageId « View previous topic :: View next topic » 
Author Message
Praveen
PostPosted: Wed Feb 12, 2003 2:39 am    Post subject: How to get the messages with the proper MessageId Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Hi All,
While putting the messages I am setting the messageId as inMsg.messageId = MQC.MQCI_NONE, now I want to get the response by checking the particular messageId, how should I do it?.
If I do like this while getting the message, will it work?
gmo.matchOptions = MQC.MQMO_MATCH_MSG_ID, is it going to give me the correct output for which I had sent?.
_________________
Thanks,

Praveen K
Back to top
View user's profile Send private message
vennela
PostPosted: Wed Feb 12, 2003 6:33 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Praveen:

Take a look at the reply to a post made bu Duncan(point 2). That would explain you how to use messageId and correlId.

http://www.mqseries.net/phpBB2/viewtopic.php?t=7298&highlight=paradigm

This is from the java manual
    For an MQQueue.put() call, this specifies the message identifier to use. If
    MQC.MQMI_NONE is specified, the queue manager generates a unique
    message identifier when the message is put. The value of this member
    variable is updated after the put to indicate the message identifier that was
    used.


So even if you use inMsg.messageId = MQC.MQCI_NONE, the unique messageId that was generated by MQ can be retrieved after you make the PUT.

In your earlier post you have posted only one side of the application. You haven't posted the other application code, so, it's hard to tell.

In the other (receiving) application what you have to do is grab the incoming message's messageId and put that in the correlId of the outgoing message

In your fisrt program even if you uncomment this line
    gmo.matchOptions = MQC.MQMO_MATCH_CORREL_ID;

I think it will work.

Hope atleast this will make things clearer

-------
Venny


Last edited by vennela on Wed Feb 12, 2003 10:39 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Praveen
PostPosted: Wed Feb 12, 2003 10:20 am    Post subject: Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Venny,

Other application sends back the message with messageID the same as the messagesID for the message they receive from our application. For CorrelationID, they set it to NONE when send back any message to our application. In this case I need to recieve the messages by checking the proper messsageId instead correlationId,right?. So can I do like this?
While putting the message
inMsg.messageId = MQC.MQCI_NONE
And while getting it back.
outMsg.messageId = MQC.MQMO_MATCH_MSG_ID;
I am not sure whether this is right or wrong?, please tell me how to check it.
_________________
Thanks,

Praveen K
Back to top
View user's profile Send private message
bduncan
PostPosted: Wed Feb 12, 2003 10:36 am    Post subject: Reply with quote

Padawan

Joined: 11 Apr 2001
Posts: 1554
Location: Silicon Valley

When you create the request message, set the MsgId field in the MQMD to MQCI_NONE . Then, in your MQPMO structure, set the MQPMO_NEW_MSG_ID parameter. Set the CorrelId in the MQMD to MQCI_NONE.

Now, when the processing application gets the request message, processes it, and creates the reply message, you need to do the following. Set the MsgId field in the MQMD to MQCI_NONE. In your MQPMO structure, set the MQPMO_NEW_MSG_ID parameter. Finally, set the CorrelId in the MQMD to the MsgId of the request message.

Now, the application looking for the reply message should be using the match option MQMO_MATCH_CORREL_ID, and set the CorrelId in the MQMD that you pass to the MQGET call to value of the MsgId that was set in the MQMD of the request message after you made your MQPUT.

The thing wrong with your scheme is that your reply message ends up having the same MsgId as the request message. This is wrong, because MsgId is supposed to be a unique identifier - no to messages should have the same value. It is more appropriate to use the CorrelId to retrieve the specific reply message. So to illustrate, if your application put a request message, it might look like:

REQUEST MESSAGE
MsgId: 555555
CorrelId:

REPLY MESSAGE
MsgId: 754321
CorrelId: 555555

And the application which made the original request will be looking for a reply message with a CorrelId matching the MsgId of the request message, or 555555.
_________________
Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator
Back to top
View user's profile Send private message Visit poster's website AIM Address
vennela
PostPosted: Wed Feb 12, 2003 10:50 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Sorry, I have missed to include the URL I was referring to in my earlier post.

I have updated the original post.

http://www.mqseries.net/phpBB2/viewtopic.php?t=7298&highlight=paradigm

-------
Venny
Back to top
View user's profile Send private message Send e-mail Visit poster's website
bduncan
PostPosted: Wed Feb 12, 2003 11:25 am    Post subject: Reply with quote

Padawan

Joined: 11 Apr 2001
Posts: 1554
Location: Silicon Valley

Funny, I thought I was typing something I'd already typed before
Thanks for jogging my memory Venny... Hopefully I'll use the search button before I spend another 15 minutes typing away...
_________________
Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator
Back to top
View user's profile Send private message Visit poster's website AIM Address
Praveen
PostPosted: Wed Feb 12, 2003 12:56 pm    Post subject: Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Brandon,
This is how I have to do right?, please correct me if I am wrong.




Code:
 MQMessage inMsg = new MQMessage();

 inMsg.messageId = MQC.MQCI_NONE;
 inMsg.correlationId = MQC.MQCI_NONE;

 MQPutMessageOptions pmo = new MQPutMessageOptions();

 pmo.options = MQC.MQPMO_NEW_MSG_ID;

 MQGetMessageOptions gmo = new MQGetMessageOptions();

 gmo.matchOptions = MQC.MQMO_MATCH_CORREL_ID;

Other application sends back the message with messageID the same as the messagesID for the message they receive from our application. For CorrelationID, they set it to NONE when send back any message to our application. They cannot change their code now. I have to make my code to work for this. Will the above solution work for this kind of response from the other application?, if not what is the alternative I need to use?.
Thanks for your response.
_________________
Thanks,

Praveen K
Back to top
View user's profile Send private message
bduncan
PostPosted: Wed Feb 12, 2003 2:48 pm    Post subject: Reply with quote

Padawan

Joined: 11 Apr 2001
Posts: 1554
Location: Silicon Valley

Well I suppose if you can't change the other application then we're stuck using the MsgId. So I would say that your code looks correct, except that you need to load the MsgId value you wish to match against into the MsgId field of the MQMessage object that you are passing into the MQGET call. I think this is what you are missing...
_________________
Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator
Back to top
View user's profile Send private message Visit poster's website AIM Address
Praveen
PostPosted: Thu Feb 13, 2003 6:27 am    Post subject: Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Brandon,
So now my code should look like this
Before putting the message

Code:

  inMsg.messageId = MQC.MQCI_NONE;
     

While getting it
Code:
       
 gmo.matchOptions = MQC.MQMO_MATCH_MSG_ID

is it right?.
_________________
Thanks,

Praveen K
Back to top
View user's profile Send private message
bduncan
PostPosted: Thu Feb 13, 2003 10:50 am    Post subject: Reply with quote

Padawan

Joined: 11 Apr 2001
Posts: 1554
Location: Silicon Valley

Right, but as I said, in addition to what you already have, you must tell the queue manager which MsgId to match against. If you simply do an MQGET and say MQC.MQMO_MATCH_MSG_ID, the queue manager has no idea which MsgId you wish to match against. When the MQGET is successful, you end up with a message object right? Well, when you pass this object to your MQGET call, you must populate the MsgId field with the MsgId that you are looking to match against.
_________________
Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator
Back to top
View user's profile Send private message Visit poster's website AIM Address
Praveen
PostPosted: Thu Feb 13, 2003 11:38 am    Post subject: Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Brandon,
Can you please send me a piece of code how to do that. Sorry for the trouble.
_________________
Thanks,

Praveen K
Back to top
View user's profile Send private message
Praveen
PostPosted: Fri Feb 14, 2003 4:20 am    Post subject: Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Brandon/Venny,
Can you please send me the code, I mean to how to set the msgId while putting and getting the messages?
_________________
Thanks,

Praveen K
Back to top
View user's profile Send private message
bduncan
PostPosted: Fri Feb 14, 2003 10:19 am    Post subject: Reply with quote

Padawan

Joined: 11 Apr 2001
Posts: 1554
Location: Silicon Valley

Praveen,
I'm sorry but I don't have the exact code you are seeking (and really don't have the time to sit down and write it right now - sorry) I would recommend looking at the Java samples in the software repository. You will probably find something that shows how to do an MQGET while matching against something...
_________________
Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator
Back to top
View user's profile Send private message Visit poster's website AIM Address
vennela
PostPosted: Fri Feb 14, 2003 11:39 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Praveen:

I have written a small program that would PUT to a queue QUEUE1 and get from the same Queue by matching the message Id. Hope this will help you in building your application:

Code:

import com.ibm.mq.*;
public class SendAndReceive extends Object {

   
    public SendAndReceive() {
    }

    /**
    * @param args the command line arguments
    */
    public static void main (String args[]) {
   
        try {

            String QM1 = "FMCQM";
            String QUEUE1 = "HELLOWORLD";
           
            System.out.println("Starting SendAndReceive Program: ");           
MQQueueManager qmgr = new MQQueueManager(QM1 ) ;
System.out.println("Connected to QMGR " + QM1);

int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING  |     MQC.MQOO_SET_IDENTITY_CONTEXT;
MQQueue InQueue = qmgr.accessQueue(QUEUE1 , openOptions, null, null, null);


MQMD messageDesc = new MQMD();
messageDesc.replyToQueueName = "HELLOWORLD";
messageDesc.replyToQueueManagerName = "WMTQM";
messageDesc.userId = "ADMIN";
MQMessage inMessage = new MQMessage();
inMessage.writeString("What is your name");
InQueue.put(inMessage);
System.out.println("Message Id is :" + inMessage.messageId);
InQueue.close();


int openOptionsForGet = MQC.MQOO_INPUT_SHARED ;
MQQueue OutQueue = qmgr.accessQueue(QUEUE1 , openOptionsForGet, null, null, null);
MQGetMessageOptions gmo = new MQGetMessageOptions() ;

MQMessage outMessage = new MQMessage();

outMessage.messageId = inMessage.messageId;
gmo.matchOptions = MQC.MQMO_MATCH_MSG_ID;
OutQueue.get(outMessage, gmo);


String msgTxt = outMessage.readString(outMessage.getMessageLength());

System.out.println (" The message is \n" + msgTxt);
OutQueue.close();
qmgr.disconnect() ;

}
catch(MQException ex){
    System.out.println("MQ Error - Reason code :" + ex.reasonCode);
}
catch (Exception e){
    System.out.println("Error : " + e);
}
       
    }

}


Notice the following three lines of code:


MQMessage outMessage = new MQMessage();

outMessage.messageId = inMessage.messageId;
gmo.matchOptions = MQC.MQMO_MATCH_MSG_ID;
OutQueue.get(outMessage, gmo);


-------
Venny
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Praveen
PostPosted: Mon Feb 17, 2003 5:12 am    Post subject: Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Venny,
Thank you very much for the code.
In the multiple user session enviroment this code should work fine right?, I mean if one user sends a request to server then he will get the response for his input only and other users for their inputs, right?.(that is what I want basically).
One more thing, will it slow down the process?, because after adding this i,e checking with the proper msgIds I am getting the reply very late.
_________________
Thanks,

Praveen K
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ Installation/Configuration Support » How to get the messages with the proper MessageId
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.