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 » MQ API to get the date of the message

Post new topic  Reply to topic Goto page Previous  1, 2
 MQ API to get the date of the message « View previous topic :: View next topic » 
Author Message
jefflowrey
PostPosted: Wed Apr 04, 2007 5:05 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

The Using Java manual is divided into half - one half talks about using the WebSphere MQ API For Java and the other half talks about using JMS.

Generally, it's the "first" half that talks about the API you are trying to use.

But again, please don't try and process messages based on timestamp. What business requirement is leading you to this technical requirement? In other words, why do you want to process messages based on timestamp?
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
michael.shapira
PostPosted: Wed Apr 04, 2007 5:16 am    Post subject: Reply with quote

Novice

Joined: 03 Apr 2007
Posts: 14

Thank you all.
It was all the time in from of me
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()
               GregorianCalendar gc= message.putDateTime;
               //message.readFully(b);
               strMsg = new String(gc.getTime().toString());
               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(gc.getTime().toString()));
               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);
      }
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Apr 04, 2007 5:23 am    Post subject: Reply with quote

Grand High Poobah

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

Well done you for working it out.

It's still a bad idea. Just because you can do a thing, does not mean it's wise to do a thing.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
michael.shapira
PostPosted: Wed Apr 04, 2007 5:24 am    Post subject: Reply with quote

Novice

Joined: 03 Apr 2007
Posts: 14

Another question. How can I know the time offset between MQ and client?
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Apr 04, 2007 5:29 am    Post subject: Reply with quote

Grand High Poobah

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

michael.shapira wrote:
How can I know the time offset between MQ and client?


Ask the guy who sets the clocks....

Seriously, it's based on system time. So there's no direct correlation between the putime in the message (which could have come from a remote queue manager on a different machine), the time of the queue manager you're cliented onto and the time on the machine running the client.

I said this solution was going to cause you problems.......
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Apr 04, 2007 1:47 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

And remember the time on the MQ message is always GMT.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
michael.shapira
PostPosted: Thu Apr 05, 2007 3:39 am    Post subject: Reply with quote

Novice

Joined: 03 Apr 2007
Posts: 14

What do you mean "always GMT". I am currently in GMT+2 and put remotly a message to the queue. In my client the time was 15:02, when I connected to the MQ server and browsed the queue. I see that put time is also 15:02. The MQ server is in the same room as the client. According to what you say, MQ should correct the time to 13:02, but it didn't happened
Back to top
View user's profile Send private message
EddieA
PostPosted: Thu Apr 05, 2007 10:37 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

That could depend on what you browsed the queue with. Some of the GUI's "adjust" the times to Local. You need to dump the message with something like amqsbcg.

Cheers.
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Apr 05, 2007 1:16 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

To access the header data you have to access the MQMD or message descriptor.

Poking around in the java directory and the "using java" manual you should find enough examples to get you going. Just remember that the times on MQ messages are ALWAYS in GMT/UTC and that if your servers don't subscribe to a time synchronization service it may be a moot point anyway...

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Goto page Previous  1, 2 Page 2 of 2

MQSeries.net Forum Index » IBM MQ Java / JMS » MQ API to get the date of the message
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.