JMS/MQRFH2 Message Properties in “other” Folder

On StackOverflow, someone asked about having an “other” folder (not “usr”) with an MQRFH2 (aka JMS) message.

That day, I played around with a MQ/Java program that created various folders in an MQRFH2 message.
i.e.

MQMessage sendmsg = new MQMessage();
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);
// type of JMS message
rfh2.setFieldValue("mcd", "Msd", "jms_text");
rfh2.setFieldValue("jms", "Dst", "queue:///"+outputQName);
// set named properties in the "usr" folder
rfh2.setFieldValue("usr", "SomeNum", 123);
rfh2.setFieldValue("usr", "SomeText", "TEST");
// set named properties in the "other" folder
rfh2.setFieldValue("other", "thingA", 789);
rfh2.setFieldValue("other", "thingB", "XYZ");
// Set the MQRFH2 structure to the message
rfh2.write(sendmsg);
sendmsg.writeString("This is a test message.");
// IMPORTANT: Set the format to MQRFH2 aka JMS Message.
sendmsg.format = CMQC.MQFMT_RF_HEADER_2;
// put the message on the queue
queue.put(sendmsg, pmo);

When I ran a MQ/JMS program to retrieve the messages, the MQ/JMS programs simply ignore all folders outside of ‘mcd’, ‘jms’ and ‘usr’.

QueueReceiver receiver = session.createReceiver(myQ);
Message inMessage = receiver.receive();
String thing = inMessage.getStringProperty("other.thingB");
System.out.println("   thing="+thing);

Enumeration<String> props = inMessage.getPropertyNames();
if (props != null)
{
   while (props.hasMoreElements())
   {
      String propName = props.nextElement();
      Object o = inMessage.getObjectProperty(propName);
      System.out.println("   Name="+propName+" : Value="+o);
   }
}

Any named properties in the “other” folder are simply ignored by the JMS framework.

If you are wondering about C programs, yes, they can get access named properties in the “other” folder. When using the MQINQMP API call, there is no parameter for the folder name, so you code it as a qualifier to the name keyword. i.e. “other.thingB”

MQCHARV  inqname = {(MQPTR)(char*)"other.thingB", 0, 0, 12, MQCCSI_APPL};
impo.Options = MQIMPO_INQ_NEXT;
impo.ReturnedName.VSPtr = name;
impo.ReturnedName.VSBufSize = sizeof(name)-1;
type = MQTYPE_STRING;
MQINQMP(Hcon, Hmsg, &impo, &inqname, &pd, &type, sizeof(value)-1, value, &datalen, &CompCode, &Reason );
printf("property name <%s> value <%s>\n", name, value);

So, if you want to use a folder called “other”, that is fine, so long as you don’t want the information to be used by a JMS/MQ program, otherwise, you need to put the name/value properties in the ‘usr’ folder.

Regards,
Roger Lacroix
Capitalware Inc.

This entry was posted in C, IBM i (OS/400), IBM MQ, Java, JMS, Linux, macOS (Mac OS X), Programming, Unix, Windows, z/OS.

Comments are closed.