|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
how to get timestamp from message without using JMS API |
« View previous topic :: View next topic » |
Author |
Message
|
mr_shuchun |
Posted: Tue May 15, 2007 12:52 am Post subject: how to get timestamp from message without using JMS API |
|
|
Newbie
Joined: 21 Sep 2006 Posts: 9
|
I want to improve the performance of MQ monitoring tool.
now it is implemented using both JMS API and JMS implelmentation API, I want to find a better way to get timesatamp of oldest message and deepth of queue. see the code fragment as followed:
..
QueueSession session =
conn.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
Queue q = session.createQueue(dest.getQueueName());
QueueBrowser browser = session.createBrowser(q);
Enumeration e = browser.getEnumeration();
long ts = 0L;
while (e.hasMoreElements()) {
if (msgCount == 0L) {
ts = msg.getJMSTimestamp();
}
msgCount++;
}
....
I have no problem to get deepth of queue using MQ base API.
but it has not such a method to get timestamp so I have to write some code to extract timestamp manualy.
<Tms>1179215965211</Tms>
does anyone have existing example to extract the timestamp or have other suggestion?
appreciate for your help! |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue May 15, 2007 1:57 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You mean you want to get the put date and the put time - that JMS magically converts into a seconds-since-epoch number? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
mr_shuchun |
Posted: Tue May 15, 2007 5:21 pm Post subject: |
|
|
Newbie
Joined: 21 Sep 2006 Posts: 9
|
jefflowrey wrote: |
You mean you want to get the put date and the put time - that JMS magically converts into a seconds-since-epoch number? |
no, JMS didn't also converts it and just return long value by calling getJMSTimestamp(), I can convert it to date and time previously.
The question is that when using MQ base java API, I just don't want to write code to get this long value of Timestamp by myself . now I can get MQMessage object using MQ base java API. but how to get this long value of timestamp using this MQMessage object?
Code: |
MQQueueManager mqQueueManager = null;
MQQueue mqQueue = null;
try {
// Create a connection to the queue manager
mqQueueManager = new MQQueueManager(queueManager);
// Set up the options on the queue we wish to open...
// Note. All MQ Options are prefixed with MQC in Java.
int openOptions = MQC.MQOO_BROWSE | MQC.MQOO_INQUIRE;
// Now specify the queue that we wish to open, and the open
// options...
mqQueue = mqQueueManager.accessQueue(queue,
openOptions, null, null,null);
// Set the get message options..
MQGetMessageOptions mqGetMessageOptions = new
MQGetMessageOptions();
mqGetMessageOptions.options = MQC.MQGMO_BROWSE_FIRST;
MQMessage message = new MQMessage();
mqQueue.get(message, mqGetMessageOptions);
} catch (MQException ex) {
ex.printStackTrace();
System.out.println("An MQ error occurred : Completion code " + ex.completionCode + " Reason code " + ex.reasonCode);
} finally {
// Close the queue
if (mqQueue != null) {
try {
mqQueue.close();
} catch (MQException e1) {
e1.printStackTrace();
System.out.println("Failed to close MQQueue");
}
}
// Disconnect from the queue manager
try {
if (mqQueueManager != null) {
mqQueueManager.disconnect();
}
} catch (MQException e) {
e.printStackTrace();
System.out.println("Failed to disconnect MQQueueManager");
}
}
|
|
|
Back to top |
|
 |
mr_shuchun |
Posted: Tue May 15, 2007 6:39 pm Post subject: |
|
|
Newbie
Joined: 21 Sep 2006 Posts: 9
|
I understand what you said. JMSTimestamp is different from putDateTime.
JMSTimestamp is the time a message was handed off to a provider to be sent, whereas putDateTime is the time a message is put in MQ indeed.
If MQ client and MQ server keeps synchronized time, putDateTime is later than JMSTimestamp
it seems it is reasonable to use putDateTime instead of JMSTimestamp.
thank you! |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue May 15, 2007 7:41 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
mr_shuchun wrote: |
I understand what you said. JMSTimestamp is different from putDateTime.
JMSTimestamp is the time a message was handed off to a provider to be sent, whereas putDateTime is the time a message is put in MQ indeed.
If MQ client and MQ server keeps synchronized time, putDateTime is later than JMSTimestamp
it seems it is reasonable to use putDateTime instead of JMSTimestamp.
thank you! |
The difference should be in the milliseconds. Except maybe for huge messages...
I believe the JMS long to be a little bit more precise (millisecond)
MQ only uses the date / time in the MQMD. And this is recorded in UTC TZ (always).  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mr_shuchun |
Posted: Tue May 15, 2007 9:44 pm Post subject: |
|
|
Newbie
Joined: 21 Sep 2006 Posts: 9
|
fjb_saper wrote: |
mr_shuchun wrote: |
I understand what you said. JMSTimestamp is different from putDateTime.
JMSTimestamp is the time a message was handed off to a provider to be sent, whereas putDateTime is the time a message is put in MQ indeed.
If MQ client and MQ server keeps synchronized time, putDateTime is later than JMSTimestamp
it seems it is reasonable to use putDateTime instead of JMSTimestamp.
thank you! |
The difference should be in the milliseconds. Except maybe for huge messages...
I believe the JMS long to be a little bit more precise (millisecond)
MQ only uses the date / time in the MQMD. And this is recorded in UTC TZ (always).  |
no, putDateTime can contain miliseconds in MQMD Java API, whereas it didn't contain miliseconds in MQMD C API:
you can decompile MQMD to see miliseconds and I also have already conducted testing to verify it.:
public class MQMD {
public GregorianCalendar putDateTime;
....
protected final void setDateAndTime(int i, int j, int k, int l, int i1, int j1, int k1) {
/*1142*/ if (Trace.isOn()) {
/*1144*/ Trace.entry(this, "setDateAndTime");
/*1145*/ Trace.trace(2, this, "Year = " + i + " Month = " + j + " Day = " + k);
/*1146*/ Trace.trace(2, this, "Time " + l + ":" + i1 + ":" + j1);
/*1147*/ Trace.trace(2, this, "Milliseconds = " + k1);
}
/*1150*/ if (putDateTime == null) {
/*1151*/ putDateTime = new GregorianCalendar(i, j - 1, k, l, i1, j1);
} else {
/*1153*/ putDateTime.set(i, j - 1, k, l, i1, j1);
}
/*1155*/ putDateTime.setTimeZone(GMT);
/*1156*/ putDateTime.set(14, k1);
/*1158*/ if (Trace.isOn()) {
/*1160*/ Trace.exit(this, "setDateAndTime");
}
}
} |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed May 16, 2007 2:30 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Ah... but you are looking at a trace here.
I was just thinking about the content of the MQMD date and time fields....  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|