Adding Personalized data to MQ RFH2 Header

孤街浪徒 提交于 2020-01-17 06:30:28

问题


HI i am trying to add data in the RFH2 MQ header. The format for the data which i want is:

struc id : RFH
version:2
encoding:546
CodedCharSetid:437
Format:MQSTR
Flags:0
NameValeCCSID:1208
NamevalueLen:56
Namevaluedata:<mcd><msd>jms_text<Msd><Type>Hello</type></mcd>
NamvalueLen:56
NameValuedata:<jms><dst></dst></jms>
NamevalueLen:56
NameValuedata:<usr>Hi</usr>

I have the following code, but i am not understanding how to add the NameValueLen and NAMEVALUEDATA part. Can some check the code which i have written and guide me further on this?

MQMessage msg = new MQMessage();
msg.format = MQC.MQFMT_RF_HEADER_2; // Msg Format
msg.writeString(MQC.MQRFH_STRUC_ID); // StrucId 
msg.writeInt4(MQC.MQRFH_VERSION_2); // Version 
msg.writeInt4(MQC.MQRFH_STRUC_LENGTH_FIXED_2 + folderLength + 4); 
msg.writeInt4(MQC.MQENC_NATIVE); // Encoding 
msg.writeInt4(MQC.MQCCSI_DEFAULT); // CodedCharacterSetId 
msg.writeString(MQC.MQFMT_NONE); // Format (content) 
msg.writeInt4(MQC.MQRFH_NO_FLAGS); // Flags 
msg.writeInt4(1208); // NameValueCCSID = UTF-8 

回答1:


I don't know what tool you are using but it is confusing the issue. MQRFH2 has "folders". The 1st folder is ALWAYS "mcd". The 2nd folder is "jms". All folders after that are optional.

Note: The "usr" folder is where you put your user data.

Why are you not using the MQRFH2 class in MQ?

https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q030950_.htm

i.e. Here's how you should be doing it:

MQMessage mqMsg = new MQMessage();
MQRFH2 rfh2 = new MQRFH2();

rfh2.setEncoding(CMQC.MQENC_NATIVE);
rfh2.setCodedCharSetId(CMQC.MQCCSI_INHERIT);
rfh2.setFormat(CMQC.MQFMT_STRING);
rfh2.setNameValueCCSID(1208);
rfh2.setFieldValue("usr", "somefield", "somedata");

try
{
   rfh2.write(mqMsg);
}
catch (IOException e)
{
   System.err.println(e.getLocalizedMessage());
}

Note: In the above code, folders "mcd" and "jms" will be automatically created and populated.

You can blast all 3 folders ("mcd", "jms" and "usr") in 1 shot. I don't recommend it unless you know what you are doing.

rfh2.setFolderStrings(new String[]{"<mcd><Msd>jms_text</Msd></mcd>",
                                   "<jms><Dst>queue:///TEST.Q1</Dst><Pri>0</Pri></jms>",
                                   "<usr><somefield>somedata</somefield></usr>"});


来源:https://stackoverflow.com/questions/43430134/adding-personalized-data-to-mq-rfh2-header

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