| Author | 
		  Message
		 | 
		
		  | meriton | 
		  
		    
			  
				 Posted: Wed Aug 21, 2002 5:13 pm    Post subject: Browsing a queue with MQMO_MATCH_CORREL_ID option. | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 07 Aug 2002 Posts: 24
  
  | 
		  
		    
			  
				Here is what I am doing get an mq error 2046
 
 
 
 
public static int doBrowseReply(byte[] corrId)
 
		throws MQException, Exception {
 
		int counter = 0;
 
		if (mQMgr != null) {
 
			try {
 
				int vOpenOptions = MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING;
 
				String vReplyQName = mReplyQName;
 
				MQQueue vReplyQ =
 
					mQMgr.accessQueue(vReplyQName, vOpenOptions, null, null, null);
 
				//testing...
 
				if (vReplyQ == null)
 
					mLog.warning("doBrowseReplyQueue - Couldn't access Reply Queue");
 
				//end testing...
 
				for (int i = 0;; i++) {
 
					MQMessage vMsg = new MQMessage();
 
					MQGetMessageOptions vMsgOptions = new MQGetMessageOptions();
 
					vMsgOptions.options = MQC.MQGMO_WAIT;
 
					vMsgOptions.options = MQC.MQMO_MATCH_CORREL_ID;
 
					vMsgOptions.waitInterval = 2000; //milliseconds
 
					if (i == 0)
 
						vMsgOptions.options = vMsgOptions.options | MQC.MQGMO_BROWSE_FIRST;
 
					else
 
						vMsgOptions.options = vMsgOptions.options | MQC.MQGMO_BROWSE_NEXT;
 
					vMsg.correlationId = corrId;
 
					vReplyQ.get(vMsg, vMsgOptions);
 
					vMsg.setDataOffset(0);
 
					
 
					String vMsgText = vMsg.readString(vMsg.getMessageLength());
 
					mLog.debug("Message " + (i + 1) + " = " + vMsgText);
 
					
 
					counter++;
 
					vMsg.correlationId = null;
 
				} //end for
 
			} catch (MQException MQe) {
 
				if (MQe.reasonCode != 2033)
 
					throw MQe;
 
			} catch (Exception e) {
 
				throw e;
 
			}
 
		} //end if
 
		return counter;
 
	} //end method doBrowseQueue/** *	
 
 
 
Thanks | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | RogerLacroix | 
		  
		    
			  
				 Posted: Wed Aug 21, 2002 8:31 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Jedi Knight
 
 Joined: 15 May 2001 Posts: 3265 Location: London, ON  Canada 
  | 
		  
		    
			  
				Hi,
 
 
After only a quick review, I see 2 problems:
 
 
First Problem:
 
   
	| Code: | 
   
  
	vMsgOptions.options = MQC.MQGMO_WAIT; 
 
vMsgOptions.options = MQC.MQMO_MATCH_CORREL_ID; | 
   
 
 
The 2nd line of code overrides the 1st line.
 
   
	| Code: | 
   
  
	| vMsgOptions.options = MQC.MQGMO_WAIT + MQC.MQMO_MATCH_CORREL_ID + MQC.MQGMO_FAIL_IF_QUIESCING; | 
   
 
Note: Having the "Fail if Quiescing" is a good thing.
 
 
Second Problem:
 
   
	| Code: | 
   
  
	if (i == 0) 
 
   vMsgOptions.options = vMsgOptions.options | MQC.MQGMO_BROWSE_FIRST; 
 
else 
 
   vMsgOptions.options = vMsgOptions.options | MQC.MQGMO_BROWSE_NEXT;  | 
   
 
 
The 1st time through the loop the program is fine but on the 2nd loop you will have set BOTH "Browse First" and "Browse Next" in the options variable (because you are summing the fields). 
 
 
Change it to the following:
 
   
	| Code: | 
   
  
	if (i == 0) 
 
   vMsgOptions.options = MQC.MQGMO_WAIT + MQC.MQMO_MATCH_CORREL_ID + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_BROWSE_FIRST; 
 
else 
 
   vMsgOptions.options = MQC.MQGMO_WAIT + MQC.MQMO_MATCH_CORREL_ID + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_BROWSE_NEXT;  | 
   
 
 
 
later
 
Roger... _________________ Capitalware: Transforming tomorrow into today.
 
Connected to MQ!
 
Twitter | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | meriton | 
		  
		    
			  
				 Posted: Wed Aug 21, 2002 8:59 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 07 Aug 2002 Posts: 24
  
  | 
		  
		    
			  
				thanks Roger,
 
 
I changed the code but get the same error.
 
 
com.ibm.mq.MQException: Completion Code
 
2, Reason 2046
 
 
 
 
TIA | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | RogerLacroix | 
		  
		    
			  
				 Posted: Thu Aug 22, 2002 8:00 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Jedi Knight
 
 Joined: 15 May 2001 Posts: 3265 Location: London, ON  Canada 
  | 
		  
		    
			  
				Well, it works for me.  
 
 
Post your code again - the entire thing and I'll have a look.
 
 
Note: Use the BBCode of [code] ... [/code] around your code so that it is easier to read.
 
 
later
 
Roger... _________________ Capitalware: Transforming tomorrow into today.
 
Connected to MQ!
 
Twitter | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | meriton | 
		  
		    
			  
				 Posted: Thu Aug 22, 2002 3:15 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 07 Aug 2002 Posts: 24
  
  | 
		  
		    
			  
				Thanks Roger ,
 
 
Here is the code,that thorws a 2046 exception at mq get.
 
 
   
	| Code: | 
   
  
	 
 
   public static int doBrowseReply(byte[] corrId,int pNumMsgsInBatch)
 
      throws MQException, Exception {
 
      int counter = 0;
 
      if (mQMgr != null) {
 
         try {
 
            int vOpenOptions = MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING;
 
            String vReplyQName = mReplyQName;
 
            MQQueue vReplyQ =
 
               mQMgr.accessQueue(vReplyQName, vOpenOptions, null, null, null);
 
            //testing...
 
            if (vReplyQ == null)
 
               mLog.warning("doBrowseReplyQueue - Couldn't access Reply Queue");
 
            //end testing...
 
            for (int i = 0;; i++) {
 
               MQMessage vMsg = new MQMessage();
 
               vMsg.correlationId = corrId;
 
               MQGetMessageOptions vMsgOptions = new MQGetMessageOptions();
 
               //vMsgOptions.options = MQC.MQGMO_WAIT;
 
               vMsgOptions.waitInterval = 2000; //milliseconds
 
               
 
            if (i == 0) 
 
               vMsgOptions.options = MQC.MQGMO_WAIT + MQC.MQMO_MATCH_CORREL_ID + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_BROWSE_FIRST; 
 
            else 
 
               vMsgOptions.options = MQC.MQGMO_WAIT + MQC.MQMO_MATCH_CORREL_ID + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_BROWSE_NEXT; 
 
               vReplyQ.get(vMsg, vMsgOptions);
 
               vMsg.setDataOffset(0);
 
                        
 
               String vMsgText = vMsg.readString(vMsg.getMessageLength());
 
               mLog.debug("Message " + (i + 1) + " = " + vMsgText);
 
               
 
                        
 
            //check if batch id is the one we want...
 
            String vBatchId = getBatchId(vMsgText, false);
 
               if (vBatchId != null) {
 
                  //if (vBatchId.equalsIgnoreCase(pBatchId))
 
                  counter++;
 
                  if( pNumMsgsInBatch == counter ) break;
 
               }
 
            
 
            
 
            } //end for
 
         } catch (MQException MQe) {
 
            if (MQe.reasonCode != 2033)
 
               throw MQe;
 
         } catch (Exception e) {
 
            throw e;
 
         }
 
      } //end if
 
      return counter;
 
   } //end method doBrowseQueue/** *   
 
 | 
   
 
 | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | RogerLacroix | 
		  
		    
			  
				 Posted: Thu Aug 22, 2002 8:34 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Jedi Knight
 
 Joined: 15 May 2001 Posts: 3265 Location: London, ON  Canada 
  | 
		  
		    
			  
				He, he, he, he ...    
 
 
I saw your mistake then I made a mistake.  There is a difference between the GMO variables options and matchOptions .
 
 
Here is the corrected code. I updated 4 lines (see // RML ):
 
   
	| Code: | 
   
  
	public static int doBrowseReply(byte[] corrId,int pNumMsgsInBatch)
 
   throws MQException, Exception {
 
   int counter = 0;
 
   if (mQMgr != null) {
 
      try {
 
         int vOpenOptions = MQC.MQOO_INQUIRE + MQC.MQOO_BROWSE + MQC.MQOO_FAIL_IF_QUIESCING; // RML
 
         String vReplyQName = mReplyQName;
 
         MQQueue vReplyQ =
 
            mQMgr.accessQueue(vReplyQName, vOpenOptions, null, null, null);
 
         //testing...
 
         if (vReplyQ == null)
 
            mLog.warning("doBrowseReplyQueue - Couldn't access Reply Queue");
 
         //end testing...
 
         for (int i = 0;; i++) {
 
            MQMessage vMsg = new MQMessage();
 
            vMsg.correlationId = corrId;
 
            MQGetMessageOptions vMsgOptions = new MQGetMessageOptions();
 
            vMsgOptions.matchOptions = MQC.MQMO_MATCH_MSG_ID;   // RML
 
            vMsgOptions.waitInterval = 2000; //milliseconds
 
 
            if (i == 0)
 
               vMsgOptions.options = MQC.MQGMO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_BROWSE_FIRST; // RML
 
            else
 
               vMsgOptions.options = MQC.MQGMO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_BROWSE_NEXT; // RML
 
            vReplyQ.get(vMsg, vMsgOptions);
 
            vMsg.setDataOffset(0);
 
 
            String vMsgText = vMsg.readString(vMsg.getMessageLength());
 
            mLog.debug("Message " + (i + 1) + " = " + vMsgText);
 
 
 
            //check if batch id is the one we want...
 
            String vBatchId = getBatchId(vMsgText, false);
 
            if (vBatchId != null) {
 
               //if (vBatchId.equalsIgnoreCase(pBatchId))
 
               counter++;
 
               if( pNumMsgsInBatch == counter ) break;
 
            }
 
 
 
         } //end for
 
      } catch (MQException MQe) {
 
         if (MQe.reasonCode != 2033)
 
            throw MQe;
 
      } catch (Exception e) {
 
         throw e;
 
      }
 
   } //end if
 
   return counter;
 
} //end method doBrowseQueue/** * | 
   
 
 
 
later
 
Roger... _________________ Capitalware: Transforming tomorrow into today.
 
Connected to MQ!
 
Twitter | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | meriton | 
		  
		    
			  
				 Posted: Thu Aug 22, 2002 10:22 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 07 Aug 2002 Posts: 24
  
  | 
		  
		    
			  
				hi roger,
 
 
Its works now,could you tell me how do I count the actual messages that matched the correlationId without actually doing some processing to the message text(see my code  getBatchId()).
 
 
 
Thanks | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | RogerLacroix | 
		  
		    
			  
				 Posted: Fri Aug 23, 2002 7:27 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Jedi Knight
 
 Joined: 15 May 2001 Posts: 3265 Location: London, ON  Canada 
  | 
		  
		    
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | meriton | 
		  
		    
			  
				 Posted: Sun Aug 25, 2002 1:58 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 07 Aug 2002 Posts: 24
  
  | 
		  
		    
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |