| Author | 
		  Message
		 | 
		
		  | michael.shapira | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 3:16 am    Post subject: MQ API to get the date of the message | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 03 Apr 2007 Posts: 14
  
  | 
		  
		    
			  
				Hi All.
 
 I am using MQ API (com.ibm.mq) to connect to the WebSphere MQ.
 
Lets say tat I have several messages in my queue. How can I get the datetime when the message was put to the queue without pulling it out from the queue?
 
 
Thank you | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 3:29 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				Browse each message in turn, retrieving the put date & put time from the message header.
 
 
The Using Java manual will guide you in the methods & options needed. _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | jefflowrey | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 3:55 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Poobah
 
 Joined: 16 Oct 2002 Posts: 19981
  
  | 
		  
		    
			  
				I hope you're not writing your own monitoring solution.
 
 
The first message on the queue will be the oldest message.  
 
 
The correct approach to having several messages on a queue is to process them all until there are no messages left on the queue. _________________ I am *not* the model of the modern major general. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:19 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| jefflowrey wrote: | 
   
  
	The first message on the queue will be the oldest message.  
 
 | 
   
 
 
 
Unless the queue is delivering in priority sequence.
 
 
But yes, if the reason you're looking at datetime to work out which to process it's a bad design. _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | michael.shapira | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:22 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 03 Apr 2007 Posts: 14
  
  | 
		  
		    
			  
				No. I am looking for the date because the demand in my application is not to process messages with now-putDateTime<10 minutes.
 
 
Thank you all. Can you post a link on documentation about how to work and extract message header? | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | michael.shapira | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:27 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 03 Apr 2007 Posts: 14
  
  | 
		  
		    
			  
				I found a sample code for message browsing
 
   
	| Code: | 
   
  
	try
 
      {
 
         int openOption = 0;
 
         openOption = MQC.MQOO_BROWSE | MQC.MQOO_INPUT_SHARED ; // open options for browse & share
 
 
         q = manager.accessQueue("Q.TEST", openOption,null,null,null);
 
         System.out.println( "Open queue sucessfull... ");
 
 
         MQGetMessageOptions getMessageOptions = new MQGetMessageOptions();
 
         getMessageOptions.options = MQC.MQGMO_BROWSE_FIRST;// | MQC.MQGMO_WAIT ; //for browsing
 
         getMessageOptions.waitInterval = MQC.MQWI_UNLIMITED; // for waiting unlimted times
 
 
         // waits unlimited
 
         while(true)
 
         {
 
            MQMessage message = new MQMessage();
 
            BufferedWriter    writer ;
 
            String strMsg;
 
            try
 
            {
 
               System.out.println( "waiting for message ... ");
 
               q.get(message, getMessageOptions);
 
               System.out.println( "Get message sucessfull... ");
 
               //message.getTotalMessageLength()
 
               byte[] b = new byte[message.getTotalMessageLength()];
 
               message.readFully(b);
 
               strMsg = new String(b);
 
               System.out.println(strMsg);
 
               // if empty message, close the queue...
 
               if ( strMsg.trim().equals("") )
 
               {
 
                  System.out.println("empty message, closing the queue ...Q.TEST");
 
                  break;
 
               }
 
               message.clearMessage();
 
               writer = new BufferedWriter(new FileWriter("c:\\draft\\MQ.txt", true));
 
               writer.write ("\n");
 
               writer.write(new String(b));
 
               writer.write ("\n");
 
               writer.close();
 
               getMessageOptions.options = MQC.MQGMO_BROWSE_NEXT  ;
 
 
            }
 
             catch (IOException e)
 
             {
 
              System.out.println("IOException during GET: " + e.getMessage());
 
              break;
 
             }
 
 
 
         } // while ends here
 
      }
 
      catch ( MQException mqExp)
 
      {
 
         System.out.println("Error in opening queue ....");
 
         //System.out.println("Queue Name : " + qName);
 
         System.out.println("CC   : " + mqExp.completionCode );
 
         System.out.println("RC   : " + mqExp.reasonCode);
 
      }
 
 | 
   
 
 
but i don't see the date in the result | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:30 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| michael.shapira wrote: | 
   
  
	No. I am looking for the date because the demand in my application is not to process messages with now-putDateTime<10 minutes.
 
 | 
   
 
 
 
I'm always suspicious of designs that insert artificial delays. 
 
 
You'll also encounter some issues if you're looping through a queue of any size looking for relevant messages in that manner, especially if new messages keep being added.
 
 
I've already mentioned the Using Java manual (or it's online equivalent). _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | jefflowrey | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:32 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Poobah
 
 Joined: 16 Oct 2002 Posts: 19981
  
  | 
		  
		    
			  
				The put date and put time are not in the message body.
 
 
The code you showed only prints the message body.
 
 
It is a horrible idea to let messages pile up on a queue, and only process messages that are older than now - x, for any value of x greater than "0".
 
 
What is the business case behind the horrible technical requirement? _________________ I am *not* the model of the modern major general. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:33 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| michael.shapira wrote: | 
   
  
	| I don't see the date in the result | 
   
 
 
 
Very few applications bother with it, for reasons alluded to earlier in the post.
 
 
You'll also need something a bit wizzier than that sample to achieve your ends, for the reasons I allude to.
 
 
The MQMD PutDate and PutTime fields are mapped onto the JMS header field JMSTimestamp. _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:35 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| Vitor wrote: | 
   
  
	
 
You'll also encounter some issues  | 
   
 
 
 
Horrible is another valid description of this proposal.....    _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | jefflowrey | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:42 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Poobah
 
 Joined: 16 Oct 2002 Posts: 19981
  
  | 
		  
		    
			  
				
   
	| Vitor wrote: | 
   
  
	| The MQMD PutDate and PutTime fields are mapped onto the JMS header field JMSTimestamp. | 
   
 
 
 
The sample shown is using the base MQ API, not JMS. _________________ I am *not* the model of the modern major general. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:43 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| jefflowrey wrote: | 
   
  
	
   
	| Vitor wrote: | 
   
  
	| The MQMD PutDate and PutTime fields are mapped onto the JMS header field JMSTimestamp. | 
   
 
 
 
The sample shown is using the base MQ API, not JMS. | 
   
 
 
 
Like I said, I can get "Hello World" into a box now...             _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | jefflowrey | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:44 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Poobah
 
 Joined: 16 Oct 2002 Posts: 19981
  
  | 
		  
		    
			  
				
   
	| Vitor wrote: | 
   
  
	Like I said, I can get "Hello World" into a box now...             | 
   
 
 
 
The easiest clue is that it mostly looks like a C MQ program, with MQ Options and etc. _________________ I am *not* the model of the modern major general. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | michael.shapira | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:54 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 03 Apr 2007 Posts: 14
  
  | 
		  
		    
			  
				Let me correct myself. Indeed I am using MQ API.
 
 
About the bad desighn .... I am not Java programmer, I am mostly PL/SQL developer. When one use Oracle Application he can expect mostly stange issues that are mostly have even more strange solution.
 
 
 
I looked into Java manual. It describes the use of JMS , but I didn't find how can I get the header data with MQ API | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Wed Apr 04, 2007 4:59 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| michael.shapira wrote: | 
   
  
	When one use Oracle Application he can expect mostly stange issues that are mostly have even more strange solution.
 
 | 
   
 
 
 
But this is MQ. Your design is leading you into a bad place that can cause serious problems later on.
 
 
Or it's horrible, to use the shorthand of my estemed associate.
 
 
As to the header data, I think I've already demonstrated my lack of reliable knowledge in this area so I'll pass on that question.    _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |