| Author | 
		  Message
		 | 
		
		  | MABeatty1978 | 
		  
		    
			  
				 Posted: Tue Sep 22, 2015 8:52 am    Post subject: Subsequent get not getting | 
				     | 
			   
			 
		   | 
		
		
		   Acolyte
 
 Joined: 17 Jul 2014 Posts: 54
  
  | 
		  
		    
			  
				I've got a java application the executes an externam process which puts several messages on a queue.  It does a Process.waitFor() and when the process completes, it gets the messages
 
 
   
	| Code: | 
   
  
	boolean moreMessages = true;
 
int mqoo = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INQUIRE; 
 
MQQueue tmpQueue = qmgr.accessQueue("SYSTEM.DEFAULT.MODEL.QUEUE", mqoo, qManagerName, dynQName, null );
 
gmo.options = MQConstants.MQGMO_WAIT;
 
gmo.waitInterval = 10000;
 
MQMessage = new MQMessage();
 
 
while (moreMessages) {
 
   try{
 
      log.write("Curr depth1: " + tmpQueue.getCurrentDepth());
 
      tmpQueue.get(msg, gmo);
 
      log.write("Curr depth2: " + tmpQueue.getCurrentDepth());
 
    }
 
    catch{
 
         
 
         if (rc = 2033){
 
              log.write("Curr depth3: " + tmpQueue.getCurrentDepth());
 
              log.write("No messages Available");
 
              moreMessages = false;
 
         }
 
    }
 
 
} | 
   
 
 
 
When I run the program I get the following:
 
Curr depth1: 6
 
Curr depth2: 5;
 
Curr depth1: 5
 
----- there is a 10 second delay -----
 
Curr depth3: 5
 
No Messages Available
 
 
What is going on here?  Clearly there are still 5 more messags available, so why is it going into the Exception block with mqrc 2033?
  Last edited by MABeatty1978 on Tue Sep 22, 2015 9:02 am; edited 1 time in total | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | MABeatty1978 | 
		  
		    
			  
				 Posted: Tue Sep 22, 2015 9:01 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Acolyte
 
 Joined: 17 Jul 2014 Posts: 54
  
  | 
		  
		    
			  
				It happens every time.... mess around for 4 hours trying to figure it out...
 
 
Give up and go to the boards....
 
 
Figure it out less than 2 minutes later. 
 
 
Problem was that I defined my MQMessage msg outside of the while loop so msg was still populated when it got to the second iteration.  
 
 
The solution was to move the MQMessage msg = new MQMessage(); into the while loop so a new message was insantiated each time around.
 
 
Though.... can someone explain why?  Why didn't MQ just get the next message and over write the old one? | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | mqjeff | 
		  
		    
			  
				 Posted: Tue Sep 22, 2015 9:06 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Master
 
 Joined: 25 Jun 2008 Posts: 17447
  
  | 
		  
		    
			  
				Because you were asking it to get a message with the same MsgID. _________________ chmod  -R ugo-wx / | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | tczielke | 
		  
		    
			  
				 Posted: Tue Sep 22, 2015 11:17 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Guardian
 
 Joined: 08 Jul 2010 Posts: 943 Location: Illinois, USA 
  | 
		  
		    
			  
				Another option is to keep the code the way it was but add this into your loop after you get the message:
 
 
   
	| Quote: | 
   
  
	
 
         Arrays.fill(msg.messageId, (byte) 0);
 
         Arrays.fill(msg.correlationId, (byte) 0);
 
 | 
   
 
 
 
I write Java with a C mentality, so allocating the same object over and over again offends my programming sensibilities.    _________________ Working with MQ since 2010. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | mqjeff | 
		  
		    
			  
				 Posted: Tue Sep 22, 2015 11:32 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Master
 
 Joined: 25 Jun 2008 Posts: 17447
  
  | 
		  
		    
			  
				
   
	| tczielke wrote: | 
   
  
	| I write Java with a C mentality | 
   
 
 
 
You should teach that to Vitor.
 
         _________________ chmod  -R ugo-wx / | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | tczielke | 
		  
		    
			  
				 Posted: Tue Sep 22, 2015 11:34 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Guardian
 
 Joined: 08 Jul 2010 Posts: 943 Location: Illinois, USA 
  | 
		  
		    
			  
				You should see my Java code . . . .    _________________ Working with MQ since 2010. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | mqjeff | 
		  
		    
			  
				 Posted: Tue Sep 22, 2015 11:37 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Master
 
 Joined: 25 Jun 2008 Posts: 17447
  
  | 
		  
		    
			  
				
   
	| tczielke wrote: | 
   
  
	You should see my Java code . . . .    | 
   
 
 
 
You should see Vitor's... 
 
 
I mean, if there were any...
 
  _________________ chmod  -R ugo-wx / | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Tue Sep 22, 2015 12:29 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				That drink I promised to buy you at MQTC - how do you take your hemlock? Straight? On the rocks? _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Tue Sep 22, 2015 6:51 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				
   
	| Vitor wrote: | 
   
  
	| That drink I promised to buy you at MQTC - how do you take your hemlock? Straight? On the rocks? | 
   
 
 
On the rocks with a splash of Absinthe....   _________________ MQ & Broker admin | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | mqjeff | 
		  
		    
			  
				 Posted: Wed Sep 23, 2015 4:57 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Master
 
 Joined: 25 Jun 2008 Posts: 17447
  
  | 
		  
		    
			  
				
   
	| fjb_saper wrote: | 
   
  
	
   
	| Vitor wrote: | 
   
  
	| That drink I promised to buy you at MQTC - how do you take your hemlock? Straight? On the rocks? | 
   
 
 
On the rocks with a splash of Absinthe....   | 
   
 
 
    _________________ chmod  -R ugo-wx / | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | tczielke | 
		  
		    
			  
				 Posted: Wed Sep 23, 2015 5:01 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Guardian
 
 Joined: 08 Jul 2010 Posts: 943 Location: Illinois, USA 
  | 
		  
		    
			  
				I think Socrates preferred hemlock neat . . . _________________ Working with MQ since 2010. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | mqjeff | 
		  
		    
			  
				 Posted: Wed Sep 23, 2015 5:02 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Master
 
 Joined: 25 Jun 2008 Posts: 17447
  
  | 
		  
		    
			  
				
   
	| tczielke wrote: | 
   
  
	| I think Socrates preferred hemlock neat . . . | 
   
 
 
Socrates himself was permanently pissed. _________________ chmod  -R ugo-wx / | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |