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 » [ help ] getting message from MQ with specific correlationID

Post new topic  Reply to topic
 [ help ] getting message from MQ with specific correlationID « View previous topic :: View next topic » 
Author Message
cics_noob
PostPosted: Thu Dec 17, 2009 3:50 am    Post subject: [ help ] getting message from MQ with specific correlationID Reply with quote

Newbie

Joined: 09 Dec 2009
Posts: 2

hey folks
i'm new to MQ

Scenario:
putting a msg into a SendQ with specific messageID (actually timestamp) << send = success,
the queue manager copies the messageID to the correlationID
when i browse the messages from ReceiveQ looking for the message with the pre-specified correlationID

it doesnt work

here wat i have done :

Code:

import java.sql.Timestamp;
import java.util.Date;

import com.ibm.mq.MQC;
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;


public class test {

   /**
    * @param args
    */
   public String ConnectToMQ(String buildingInsNo) {

      MQEnvironment.hostname   = "10.240.240.201";
      MQEnvironment.channel   = "SYSTEM.ADMIN.SVRCONN";
      MQEnvironment.port      = Integer.parseInt("1414");
      String qManager = "CSQ1";
      String SendQ = "MQMT.CICS.START.QUEUE";
      String ReceiveQ = "Q1";
      Timestamp obj = new Timestamp(new Date().getTime());
      byte[] msgid_byte = null ;
      String var = "Didn't get it yet";
      
      /***************************************************************************************************************/
      /*                   Putting the message manually with message id and correlation id                           */
      /***************************************************************************************************************/
      try {
         MQQueueManager qMgr = new MQQueueManager(qManager);
         int openOptions = MQC.MQOO_OUTPUT ;
          MQQueue SDLQ = qMgr.accessQueue(SendQ,openOptions, null, null, null);
          MQMessage message = new MQMessage();
          message.writeUTF(buildingInsNo);
          MQPutMessageOptions pmo = new MQPutMessageOptions();
          msgid_byte = message.messageId;
          SDLQ.put(message,pmo);
          SDLQ.close();
          qMgr.disconnect();
      }
      catch (MQException ex) {
          System.err.println("An MQ error occurred : Completion code " +
                             ex.completionCode +
                             " Reason code " + ex.reasonCode);
        } catch (java.io.IOException ex) {
          System.err.println("An error occurred writing to message buffer: " +
                             ex);
        }
/***************************************************************************************************************/
/*                             Getting the message from Q1                                                     */
/***************************************************************************************************************/
       
        try {
         MQQueueManager qMngr = new MQQueueManager(qManager);
         int openOptions = MQC.MQOO_INPUT_EXCLUSIVE | MQC.MQOO_BROWSE;
         MQQueue myQueue = qMngr.accessQueue(ReceiveQ, openOptions,null, null, null);
         /******************************************************/
            /* Set up our options to browse for the first message */
            /******************************************************/
            MQGetMessageOptions gmo = new MQGetMessageOptions();
            gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
            MQMessage myMessage = new MQMessage();
            boolean done = false;
            do {
               try {
                  /*****************************************/
                   /* Reset the message and IDs to be empty */
                   /*****************************************/
                   myMessage.clearMessage();
                   myMessage.correlationId = MQC.MQCI_NONE;
                   myMessage.messageId = MQC.MQMI_NONE;
                   myQueue.get(myMessage, gmo);
                   byte[] corr_byte = myMessage.correlationId;
                   var = myMessage.readLine();
                   System.err.println("Browsed message: " + var);
                   System.err.println(">>>>>>>> correlationID  = "+corr_byte);
                   System.err.println(">>>>>>>> msgid.getbytes = "+ msgid_byte);
                   if (corr_byte.equals(msgid_byte)) {
                       System.err.println(">>>>>>>>>> FOUND <<<<<<<<<<");
                       gmo.options = MQC.MQGMO_MSG_UNDER_CURSOR;
                       myQueue.get(myMessage, gmo);
                       var = myMessage.readLine();
                    }
                   /************************************************/
                   /* Reset the options to browse the next message */
                   /************************************************/
                   gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;
               }catch (MQException ex) {
                   /**************************************************/
                   /* Probably encountered our no message available: */
                   /* write out error and mark loop to be exited     */
                   /**************************************************/
                   System.out.println("MQ exception: CC = " + ex.completionCode
                                      + " RC = " + ex.reasonCode);
                   done = true;
                } catch (java.io.IOException ex) {
                   System.out.println("Java exception: " + ex);
                   done = true;
                }

            }while(!done);
            

            /**********************************************************/
            /* Before the program ends, the open queue will be closed */
            /* and the queue manager will be disconnected.            */
            /**********************************************************/
            myQueue.close();
            qMngr.disconnect();
            
      } catch (MQException e) {
         e.printStackTrace();
      }
       
      return var;
   }
   
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      test obj = new test();
      System.err.println();
      System.err.println(obj.ConnectToMQ("000000199"));
      
   }

}





Now, wat i want to do :
1- get the message i sent ( with same messageID or correlationID )
2- delete the message from the Q after i get it


iam soo stuck and REALLY help is apreciated !
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Dec 17, 2009 4:49 am    Post subject: Re: [ help ] getting message from MQ with specific correlati Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

cics_noob wrote:
i'm new to MQ


I urge you to seek formal training - this is not an easy product!

cics_noob wrote:
putting a msg into a SendQ with specific messageID (actually timestamp) << send = success,


The dangers of doing this have been discussed often on the forum. Why not use the system supplied values?

cics_noob wrote:
1- get the message i sent ( with same messageID or correlationID )


Pick one.

cics_noob wrote:
2- delete the message from the Q after i get it


That's easy - WMQ does that for you.

cics_noob wrote:
iam soo stuck and REALLY help is apreciated !


AFAIK JMS doesn't allow msgid to be set, only correl id. My comments above on doing this, even if you can, still hold.

There have also been many discussions on the dangers of treating id fields like they're strings - they're not. It's possible whatever is sending the reply is inadvertently mangling the values.

Get some training. Seriously. This is a complex product and while I'm a firm believer in learning by experimentation (and endorse your efforts) it's going to be a long and painful road for you without a formal grounding.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mvic
PostPosted: Tue Dec 22, 2009 4:13 pm    Post subject: Re: [ help ] getting message from MQ with specific correlati Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

cics_noob wrote:
the queue manager copies the messageID to the correlationID

When do you expect it to do that? I wouldn't expect it to do that.

Quote:
when i browse the messages from ReceiveQ looking for the message with the pre-specified correlationID

it doesnt work

Use the sample program /opt/mqm/samp/bin/amqsbcg to dump what is on the queue and this will help with debugging.

Quote:
Now, wat i want to do :
1- get the message i sent ( with same messageID or correlationID )
2- delete the message from the Q after i get it

1.you are on the right track. you are calling get, but I think you have got confused over what correlId is going to be in the message.
2.you are on the right track. but notice the BROWSE flags you specified in your get options. Using these flags causes MQ to leave the message on the queue.
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Dec 22, 2009 5:24 pm    Post subject: Re: [ help ] getting message from MQ with specific correlati Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mvic wrote:
cics_noob wrote:
the queue manager copies the messageID to the correlationID

When do you expect it to do that? I wouldn't expect it to do that.


Oooo...well spotted!
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
zonko
PostPosted: Tue Dec 22, 2009 11:07 pm    Post subject: Reply with quote

Voyager

Joined: 04 Nov 2009
Posts: 78

Quote:
the queue manager copies the messageID to the correlationID


the qmgr does do that when it generates report msgs
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Dec 23, 2009 5:53 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

zonko wrote:
Quote:
the queue manager copies the messageID to the correlationID


the qmgr does do that when it generates report msgs


But not in the request / reply scenario the original poster seems to be using.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » [ help ] getting message from MQ with specific correlationID
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.