Issue While Setting MQRFH2 header in IBM MQ

笑着哭i 提交于 2019-12-13 17:14:25

问题


I am trying to send an MQ Message with MD and RFH2 headers set. I need the Message to appear like this 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


回答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':

Screen-shot #2 shows the message payload in HEX format:

Screen-shot #3 shows the message properly formatted for MQRFH2:

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):

Screen-shot #5 shows the message payload in HEX format:

Screen-shot #6 shows the message payload as:

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

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




回答2:


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;


来源:https://stackoverflow.com/questions/49616262/issue-while-setting-mqrfh2-header-in-ibm-mq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!