Author |
Message
|
cronydude |
Posted: Fri Jul 18, 2003 11:04 pm Post subject: Retrieving MQ Headers other than MQMD |
|
|
 Voyager
Joined: 11 Nov 2001 Posts: 85 Location: US
|
Hi folks,
How can we retrieve and separate headers like Tranmission Queue Header, Dead Letter Queue Header etc from the messages (in transmission queues and dead letter queues) programatically especially in java?
Any help is greatly appreciated.... _________________ Regs,
crony
IBM Certified Specialist - MQSeries |
|
Back to top |
|
 |
EddieA |
Posted: Tue Jul 22, 2003 8:50 am Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
As far as the application is concerned, these will be part of the payload.
So, you would need to check the MQMD Format to see what the 1st part of the payload is. If it's an MQ Header, then you would have to read the Format from that header, to see what the next piece is. Plus skip over the header. They all have either a fixed length, of a field that contains the length. And continue doing this until you get to the data you want.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
bduncan |
Posted: Tue Jul 22, 2003 4:18 pm Post subject: |
|
|
Padawan
Joined: 11 Apr 2001 Posts: 1554 Location: Silicon Valley
|
Yes, if you look at the DeadLetterHandler program in the C++ section of the software repository, you'll see how it extracts the dead letter header from the MQMD in the fashion Eddie described... _________________ Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator |
|
Back to top |
|
 |
mqonnet |
Posted: Wed Jul 23, 2003 8:11 am Post subject: |
|
|
 Grand Master
Joined: 18 Feb 2002 Posts: 1114 Location: Boston, Ma, Usa.
|
This would be one of the very few times i gave up on a particular thing. As far as i can see, You CANNOT do this using Java. There are many reasons for this.
1) MQ support for java doesnt have something like cmqc.h to give you all the structure definitions.
2) Even if you tried to somehow make it up by yourself, the other issue that you would run into is arrays. Its not the same as in C/C++.
3) Parsing??? This is the 3rd most important issue. When you are using C/C++ structures that are using arrays, they are stored in the memory allocated to them when these were defined. Which meant, that any members of that structrue were using all of the space assigned to them. For example, you define char test[10], it would use all of 10 bytes of memory even if you have only "HI" in it as the value. Hence if you have two such data members in a class like, char test[10] followed by char test1[20] containing values "HI" and "HELLO", C/C++ looks them "as is". Because either language is looking at the actualy memory location, since these are pointers. As opposed to Java, where it is considered as a message "HIHELLO". Now how on earth would anyone figure out a way to parse them out. There is no way this is possible.
Moreover there are no methods that are supplied in either MA88 nor in 5.3 that would help you in this case.
The only solution that i think is possible even using java is calling the JNI interface. With which you write the parsing rule for the DLH structure in C/C++. Make it a dll. Call it from your java app.
Hope this helps.
Cheers
Kumar |
|
Back to top |
|
 |
EddieA |
Posted: Wed Jul 23, 2003 2:09 pm Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Kumar,
I beg to differ on that. I've written a small Java program that I use to 'investigate' messages.
Currently it understands, and displays all the fields, from the MQMDE, MQXMIT, MQDLH, and MQRFH2. Plus, if it finds that the message is an MQEVENT, it displays what the event really is.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
syangloo |
Posted: Wed Jul 23, 2003 4:34 pm Post subject: |
|
|
Centurion
Joined: 01 Oct 2002 Posts: 120 Location: Kuala Lumpur
|
Hi Eddie
Can you share you source code and some sample result to us?
Regards
Syangloo |
|
Back to top |
|
 |
mqonnet |
Posted: Wed Jul 23, 2003 4:59 pm Post subject: |
|
|
 Grand Master
Joined: 18 Feb 2002 Posts: 1114 Location: Boston, Ma, Usa.
|
Eddie, i am mystified too. If you can, share the code, you really got my curiosity level on the higher end.
In fact the only reason i was trying this was to add this code to the forums repository as many people have asked about it. Now you can do this for all of us.
Cheers
Kumar |
|
Back to top |
|
 |
EddieA |
Posted: Thu Jul 24, 2003 7:06 am Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Here's a snippet of the code, where I break down the RFH2:
Code: |
public String DisplayRFH2(MQMessage gotMessage) throws IOException {
String rfhStrucID = gotMessage.readString(4);
int rfhVersion = gotMessage.readInt();
int rfhStrucLength = gotMessage.readInt();
int rfhEncoding = gotMessage.readInt();
int rfhCodedCharSetId = gotMessage.readInt();
String rfhFormat = gotMessage.readString(8);
int rfhFlags = gotMessage.readInt();
int rfhNameValueCCSID = gotMessage.readInt();
gotMessage.characterSet = rfhNameValueCCSID;
// gotMessage.characterSet = 437; // #### Some combinations of JRE/MA88 blow up by reading too much
int hdrOffset = gotMessage.getDataOffset();
if (doHdrs.equalsIgnoreCase("yes") ||
doHdrs.equalsIgnoreCase("rfh2")) {
messageVars[0] = new String("MQRFH2");
PrintMessage(14, messageVars);
System.out.println();
System.out.println("StrucId : '" + rfhStrucID +"'");
System.out.println("Version : " + rfhVersion);
System.out.println("StrucLength : " + rfhStrucLength);
System.out.println("Encoding : " + rfhEncoding);
System.out.println("CodedCharSetId : " + rfhCodedCharSetId);
System.out.println("Format : '" + rfhFormat +"'");
System.out.println("Flags : " + new Format ("%-10i").format(rfhFlags) +
"(" + InfoString("MQRFH", rfhFlags) + ")");
System.out.println("NameValueCCSID : " + rfhNameValueCCSID);
int lenPairs;
String valuePairs;
while (hdrOffset < rfhStrucLength) {
lenPairs = gotMessage.readInt();
valuePairs = gotMessage.readString(lenPairs);
boolean didItParse = parseV(valuePairs);
if (!didItParse) {
System.out.println(InfoString("MQShowMSG", 23));
}
System.out.println("");
hdrOffset += lenPairs + 4;
};
System.out.println();
messageVars[0] = new String("MQRFH2");
PrintMessage(15, messageVars);
System.out.println();
}
else {
hdrOffset = gotMessage.skipBytes(rfhStrucLength - hdrOffset);
}
gotMessage.encoding = rfhEncoding;
gotMessage.characterSet = rfhCodedCharSetId;
return rfhFormat;
};
|
I did think about posting this, and a 'remote' runmqsc I have to the repository, but I couldn't see how too.
Plus, I am a little embarrassed about my code as my Java skills are very rudimentary.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
bower5932 |
Posted: Thu Jul 24, 2003 9:41 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I don't think you can post to the repository. I've always sent my code to Brandon and he has put it out. |
|
Back to top |
|
 |
mqonnet |
Posted: Thu Jul 24, 2003 4:58 pm Post subject: |
|
|
 Grand Master
Joined: 18 Feb 2002 Posts: 1114 Location: Boston, Ma, Usa.
|
Hmmm...
Thanks Eddie for sharing that piece of code. When i get a chance i shall try it out too.
Cheers
Kumar |
|
Back to top |
|
 |
bduncan |
Posted: Fri Jul 25, 2003 12:35 pm Post subject: |
|
|
Padawan
Joined: 11 Apr 2001 Posts: 1554 Location: Silicon Valley
|
Right... Eddie, feel free to email me anything you want posted to the repository (bduncan (AT) mqseries.net) and I'll add it for you. I just didn't want people to be adding things to the repository willy nilly since people are going to be downloading these things and executing them on their machines. The last thing I need is someone uploading a virus, so I screen everything before putting it out for general consumption.  _________________ Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator |
|
Back to top |
|
 |
capmanoj8 |
Posted: Mon Nov 27, 2006 1:20 pm Post subject: Looking for DLH reader code in Java |
|
|
Newbie
Joined: 27 Nov 2006 Posts: 1
|
Can anyone please tell me where i can get sample java code that reads DLH specifically reason field value? |
|
Back to top |
|
 |
EddieA |
Posted: Mon Nov 27, 2006 2:09 pm Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Code: |
public String DisplayDLH(MQMessage gotMessage) throws IOException {
String dlhStrucID = gotMessage.readString(4);
int dlhVersion = gotMessage.readInt();
int dlhReason = gotMessage.readInt();
String dlhDestQName = gotMessage.readString(48);
String dlhDestQMgrName = gotMessage.readString(48);
int dlhEncoding = gotMessage.readInt();
int dlhCodedCharSetId = gotMessage.readInt();
String dlhFormat = gotMessage.readString(8);
int dlhPutApplType = gotMessage.readInt();
String dlhPutApplName = gotMessage.readString(28);
String dlhPutDate = gotMessage.readString(8);
String dlhPutTime = gotMessage.readString(8);
}
|
Cheers. _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
|