1

I am trying to send an MQ Message with MD and RFH2 headers set. I need the Message to appear like this on AppWatch.

MQ MESSAGE ON APPWATCH But the RFH2 part comes as a part of Message data as a continous string.

am using the following code:

MQMessage msg = new MQMessage();
msg.writeString("Data to go as Message Content"); 

//Setting MQMD values
msg.persistence = MQConstants.MQPER_PERSISTANT;
msg.encoding = MQConstants.MQENC_S390;
msg.characterSet = 500;

//Setting RFH2 Values
MQRFH2 rfh2 = new MQRFH2();
rfh2.setEncoding(CMSQC.MQENC_NATIVE);
rfh2.setCodedCharSetId(CMSQC.MQCCSI_INHERIT);
rfh2.setFormat(CMSQC.MQFMT_STRING);
rfh2.setFlags(0);
rfh2.setNameValueCCSID(1208);
rfh2.setFieldValue("mcd","msd","jms_text");
rfh2.setNameValueData(<xml><usr><ENTRYNUM>123</ENTRYNUM><text>TEST123</text></usr></xml>);

//Setting the Header to the Message
rfh2.write(msg);

MQQueue queue = qmngr.accessQueue(qname,MQConstants.MQOO_OUTPUT);
queue.put(msg,pmo);
queue.close;

Can someone help me out in setting the RFH2 Values properly.

NOTE: The above screenshot is just a sample and code is not related to that screenshot

FAIZAN
  • 271
  • 1
  • 6
  • 16
  • Possible duplicate of [Adding Personalized data to MQ RFH2 Header](https://stackoverflow.com/questions/43430134/adding-personalized-data-to-mq-rfh2-header) – JoshMc Apr 02 '18 at 19:17
  • You asked this question already and it was answered by Roger. Based on his answer and your value you are attempting to set I believe it should just be two calls to `rfh2.setFieldValue`, no need for `rfh2.setNameValueData`. – JoshMc Apr 02 '18 at 19:19
  • `rfh2.setFieldValue("usr", "ENTRYNUM", "123");` – JoshMc Apr 02 '18 at 19:20
  • `rfh2.setFieldValue("usr", "text", "TEST123");` – JoshMc Apr 02 '18 at 19:20
  • Hi @JoshMc am actually looking for the correct format here, If you observe the code I am using exactly the same way as suggested in that thread. Buty question is y am I not able to view the message in proper format like in the sccreenshot. Is there something which I am missing here? – FAIZAN Apr 02 '18 at 19:21
  • I don't see `setNameValueData` referenced anywhere in that answer. Much better to come back and edit your original question and comment on it if you want to clarify something rather than open a new question. You have three now on this same subject. – JoshMc Apr 02 '18 at 19:23
  • @JoshMc I created new question because the last one was almost a year ago – FAIZAN Apr 02 '18 at 19:24
  • @JoshMc and out of those 3 am still not able to get the exact answer which m looking for – FAIZAN Apr 02 '18 at 19:26
  • Did you try as I suggested above? – JoshMc Apr 02 '18 at 19:30
  • Yes, but still that gets appended to the message data, doesn't appear as separate header as visible in screenshot – FAIZAN Apr 02 '18 at 19:31
  • When you edit a question it goes back to the top of the queue of questions. If you comment on a answer the person who answered will also see this comment next time they check SO. Roger is active and would probably see it. You also never accepted the answer to either prior question. If that means that it did not solve your problem you should continue to work on the question. Opening more doesn't help it just causes there to be three similar questions each with a slightly different answer and none solving the problem :) – JoshMc Apr 02 '18 at 19:31
  • Can you show a screen shot of what you mean for the "bad" message, what is the Format? – JoshMc Apr 02 '18 at 19:32
  • @JoshMc oh wasnt aware of that thank you for the info will keep that in mind 😊 – FAIZAN Apr 02 '18 at 19:33
  • Sorry I won't be able to do that, it's a client machine on which m working – FAIZAN Apr 02 '18 at 19:34
  • From another of Roger's answers: https://stackoverflow.com/questions/36721297/get-rfh2-usr-area-name-value-pairs-from-mq-queue-using-java/36753847#36753847 `MQHeaderList putList = new MQHeaderList(); putList.add(rfh2); msg.format = putList.updateHeaderChaining(CMQC.MQFMT_RF_HEADER_2);` – JoshMc Apr 02 '18 at 19:38
  • I tried the using the headerList as u suggested, but I am getting exception. Completion code 2 Reason : 2142 – FAIZAN Apr 03 '18 at 08:58
  • @JoshMc any suggestions? – FAIZAN Apr 03 '18 at 17:37
  • but MQRFH2 doesn't have write method with input field with MQMessage type! – OGSL Jun 03 '19 at 14:51

2 Answers2

1

But the RFH2 part comes as a part of Message data as a continous string.

Yes, technically speaking, MQRFH2 header and folders are part of the message body.

It appears I wasn't explicit enough in my others posts regarding MQRFH2 class. The order of how you do things is IMPORTANT.

i.e. If you do A then B your message will be AB. If you do B then A your message will be BA. MQ does NOT reorder things.

Have you ever looked at an MQRFH2 message in its raw form? see here: https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.ref.dev.doc/q099250_.htm

There are several tools that can show you the raw layout: amqsbcg, MQ Visual Edit, MO71, etc...

From your code above, you did things backwards. You added the message payload then added the RFH2 header and folders. That is garbage to MQ.

The correct sequence should be MQRFH2 followed by message payload.

MQMessage msg = new MQMessage();

//Setting RFH2 Values
MQRFH2 rfh2 = new MQRFH2();
rfh2.setEncoding(CMQC.MQENC_NATIVE);
rfh2.setCodedCharSetId(CMQC.MQCCSI_INHERIT);
rfh2.setFormat(CMQC.MQFMT_STRING);
rfh2.setFlags(0);
rfh2.setNameValueCCSID(1208);
rfh2.setFieldValue("usr", "ENTRYNUM", "123");
rfh2.setFieldValue("usr", "text", "TEST123");

//Setting the Header to the Message
rfh2.write(msg);

msg.writeString("Data to go as Message Content");

//Setting MQMD values
msg.persistence = CMQC.MQPER_PERSISTANT;
msg.format = CMQC.MQFMT_RF_HEADER_2;

MQQueue queue = qmngr.accessQueue(qname, CMQC.MQOO_FAIL_IF_QUIESCING + CMQC.MQOO_OUTPUT);
queue.put(msg,pmo);
queue.close;

Update April 5th 2018.

Ok Faizan, by your comments below, you still are not getting it.

I ran a sample JMS MQ program I have and it put the following message data on the queue: "Nice simple test. Time in 'ms' is -> 1522946795894".

Note: I changed my MQ Visual Edit Preferences from "Show message properties as Named Properties" to "Show message properties as an MQRFH2 structure in message body". (see bottom of this posting about MQGetMessageOptions for more info).

The first 3 screen-shots from MQ Visual Edit shows you how the message looks in the queue (as you are seeing it):

Screen-shot #1 shows that the MQMD Format of the message is 'MQHRF2': enter image description here

Screen-shot #2 shows the message payload in HEX format: enter image description here

Screen-shot #3 shows the message properly formatted for MQRFH2: enter image description here

If I switch MQ Visual Edit's Preferences back to "Show message properties as Named Properties" then (THIS IS EXACTLY THE SAME MESSAGE):

Screen-shot #4 shows that the MQMD Format of the message is 'MQSTR' (string): enter image description here

Screen-shot #5 shows the message payload in HEX format: enter image description here

Screen-shot #6 shows the message payload as: enter image description here

Screen-shot #7 shows that all the values from the MQRFH2 folders are now Named Properties: enter image description here

Note: In both cases, it is the SAME message but the difference is how you want the RECEIVING application to handle it.

The MQGetMessageOptions class has an option field called 'options'. You can add (OR) either MQGMO_PROPERTIES_IN_HANDLE or MQGMO_PROPERTIES_FORCE_MQRFH2 option to that field. Right now, you appear to be using MQGMO_PROPERTIES_FORCE_MQRFH2. See here for more info: https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.ref.dev.doc/q096780_.htm

Roger
  • 7,062
  • 13
  • 20
  • Hi @Roger thank you for the solution, i understood about the part where you explained about the sequencing. I tried the above solution you gave me but still facing the issue, the rfh2 header does not appear as a separate part as in the screenshot. **It still appears in the message data part but this time before the message content** – FAIZAN Apr 04 '18 at 17:06
  • Following is the content of Message data that is visible in AppWatch when i tried the code provided by you:. **RFH[x00][x00][x00][x02][x00][x00][x00]'[x00][x00][x02]"[x00][x00] [x01]μMQSTR[x00][x00][x00][x00][x00][x04],[x00][x00][x00]8 123TEST123 Data to go as Message Content** – FAIZAN Apr 04 '18 at 17:07
  • Ding, ding, ding - we have a winner. Give that man a teddy bear!! That IS a properly formatted MQRFH2 message (aka JMS message). If you STILL don't understand then go read the IBM link that I gave above. – Roger Apr 04 '18 at 17:50
  • Lol was that a joke? Oh...!!! that was funny I would give you that , anyways m a beginner in MQ, So may be m not able to understand your solution or you are not getting my query. Anyways Thanks for your interest though. I would rather wait for someone to explain me the reason of y the RFH2 part doesnot appear as in the Screenshot. – FAIZAN Apr 04 '18 at 18:17
  • Actually, it is you that is not understanding and making a bad assumption. If you read the IBM link I gave you, you would understand. MQRFH, MQRFH2, MQCIH, MQDEAD, MQIIH, MQXMIT, etc. messages all have EMBEDDED header structures in the message payload. Embedded messages means that the message payload will have BOTH the header structure AND the application's message data. And here's something that will totally twist your noodle: in the message payload, you can have MQRFH2 & message data then another MQRFH2 & message data, another MQRFH2 & message data. ALL in the SAME message payload. – Roger Apr 04 '18 at 22:05
  • @FAIZANAHMEDKHAN Are you still setting the ccsid of the message to 500? – JoshMc Apr 05 '18 at 06:04
  • @FAIZANAHMEDKHAN I suggest you provide a screen shot of the message that you think is incorrect, this will let us see what you are seeing. – JoshMc Apr 05 '18 at 07:17
  • @JoshMc no ccsid m setting to 1208 – FAIZAN Apr 05 '18 at 08:19
  • @FAIZANAHMEDKHAN In your question you posted code `msg.encoding = MQConstants.MQENC_S390; msg.characterSet = 500;`, is this no longer done? – JoshMc Apr 05 '18 at 08:21
  • No i have removed that part now, and the code is similar to what Roger has suggested – FAIZAN Apr 05 '18 at 08:28
  • @JoshMc, I can't take the screenshot of the out put But this is what it looks like in Message data tab::::::: **RFH[x00][x00][x00][x02][x00][x00][x00]'[x00][x00][x02]"[x00][x00] [x01]μMQSTR[x00][x00][x00][x00][x00][x04],[x00][x00][x00]8 123TEST123 Data to go as Message Content** – FAIZAN Apr 05 '18 at 08:29
  • @FAIZANAHMEDKHAN I'm more interested in what the MQ Message Header shows. – JoshMc Apr 05 '18 at 08:43
  • @FAIZANAHMEDKHAN see my updates above with the screen-shots added. – Roger Apr 05 '18 at 17:24
  • Hi Roger I noticed you added `msg.format = CMQC.MQFMT_RF_HEADER_2;`, I think that may be what was causing his issue with the program that views the messages. – JoshMc Apr 06 '18 at 20:56
  • I had it originally but somehow it got lost when I was copying & pasted it. Yeah, if he didn't set the MQMD Format field then it would remain blank, hence, MQ or any application would not know that the message payload was a JMS message. – Roger Apr 06 '18 at 23:07
  • Thank you for the great sample code you provide on here and your site for the community! – JoshMc Apr 06 '18 at 23:43
  • @Roger Thanks for your help. So the solution you provided was to edit the preference of the viewer which i am using to view the message. – FAIZAN Apr 10 '18 at 18:50
1

I was able to view the message as displayed in the screenshot by modifying the code a bit and not using the MQRFH2 class.

I also had to take into consideration the point suggested by Roger in his answer to set the headers first and then the message payload.

reference :http://www.mqseries.net/phpBB2/viewtopic.php?t=35456

  String m_usr_data = "<usr><ENTRYNUM>123</ENTRYNUM><text>TEST123</text></usr>"
  MQMessage msg = new MQMessage();

  //Setting MQMD values
  msg.persistence = CMQC.MQPER_PERSISTANT;
  msg.format = CMQC.MQFMT_RF_HEADER_2;

  //Setting RFH2 Values
  msg.writeString(rfhStrucID);      //StrucID 
  msg.writeInt4(rfhVersion);        //Version 
  msg.writeInt4(rfhStrucLength );     //StrucLength 
  msg.writeInt4(CMQC.MQENC_NATIVE);       //Encoding 
  msg.writeInt4(CMQC.MQCCSI_INHERIT); //CodedCharSetID 
  msg.writeString(CMQC.MQFMT_STRING);       //Format 
  msg.writeInt4(0);          //Flags 
  msg.writeInt4(1208); //NameValueCCSID 
  msg.writeInt4(m_usr_data.getBytes().length);//NameValueLength <usr> 
  msg.writeString(m_usr_data);      //NameValueData <usr> 
  msg.write(rfhDataBytes);       //Actual MESSAGE data 

  msg.writeString("Data to go as Message Content");

  MQQueue queue = qmngr.accessQueue(qname, CMQC.MQOO_FAIL_IF_QUIESCING + CMQC.MQOO_OUTPUT);
  queue.put(msg,pmo);
  queue.close;
FAIZAN
  • 271
  • 1
  • 6
  • 16
  • Bad idea. Really bad idea. I can see several problems: (1) missing 'mcd' folder, (2) missing 'jms' folder, (3) all folders MUST be padded with blanks and aligned to 4 byte boundary. Go back to using the MQRFH2 class and make sure you set the message's Format field to CMQC.MQFMT_RF_HEADER_2 as per my sample. – Roger Apr 10 '18 at 20:20
  • Yeah u r right, there were 2 folders missing in the code. Thanks for pointing out I will my updated the code in my answer. – FAIZAN Apr 11 '18 at 00:01
  • And coming to part of going back to using MQRFH2 class, I will not be doing that coz even though it sets the message with rfh2 header, we have a JMS application which complained that their app could not read any data from rfh2 header, I mean they were getting null while reading data from rfh2 . Once I modified the code they were able to read it. – FAIZAN Apr 11 '18 at 00:05
  • @Roger apart from those 3 things you have mentioned that I have missed including in my code here. Why do u suggest me to go back to using MQRFH2 class? – FAIZAN Apr 11 '18 at 00:07
  • Ok. I created a complete working example for you and posted it to my blog at http://www.capitalware.com/rl_blog/?p=4823 Hence, have a read and then use the MQRFH2 class rather than hacking together your own thing. – Roger Apr 11 '18 at 17:58
  • @Roger Thank you from the example you created and posted on that blog – FAIZAN Apr 12 '18 at 15:50