Author |
Message
|
jefflowrey |
Posted: Wed Apr 04, 2007 5:05 am Post subject: |
|
|
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 |
|
 |
michael.shapira |
Posted: Wed Apr 04, 2007 5:16 am Post subject: |
|
|
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 |
|
 |
Vitor |
Posted: Wed Apr 04, 2007 5:23 am Post subject: |
|
|
 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 |
|
 |
michael.shapira |
Posted: Wed Apr 04, 2007 5:24 am Post subject: |
|
|
Novice
Joined: 03 Apr 2007 Posts: 14
|
Another question. How can I know the time offset between MQ and client? |
|
Back to top |
|
 |
Vitor |
Posted: Wed Apr 04, 2007 5:29 am Post subject: |
|
|
 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 |
|
 |
fjb_saper |
Posted: Wed Apr 04, 2007 1:47 pm Post subject: |
|
|
 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 |
|
 |
michael.shapira |
Posted: Thu Apr 05, 2007 3:39 am Post subject: |
|
|
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 |
|
 |
EddieA |
Posted: Thu Apr 05, 2007 10:37 am Post subject: |
|
|
 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 |
|
 |
fjb_saper |
Posted: Thu Apr 05, 2007 1:16 pm Post subject: |
|
|
 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 |
|
 |
|