RFH2 - What is the format of the header? - ibm-mq

I try to build an xml message to inject it in IBM MQ.
The format to be used should be RFH2. Do you know, do you have any documentation about the format (xsd?) of the header?
Thank you.

MQ's RFH2 is an extensible header consisting of a fixed-format binary structure followed by a variable portion with an XML-like syntax.
The structure is described (in basic terms) in the Knowledge Center here:
https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.1.0/com.ibm.mq.ref.dev.doc/q099070_.htm
Some MQ clients (for example JMS and .NET) will automatically prefix the messages they send with an RFH2 header. If you are using one of these clients then you might not need to encode the RFH2 yourself - it will be added for you.
Do you have any more information about why the application needs an RFH2 header?
The RFH2 is often used to carry message properties so you will need to ensure that you encoded these correctly if you are building your own RFH2.
If the application is using the MQ JMS or .NET client then it will be expecting the RFH2 header in the message to be formatted as described in the following topic:
https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.1.0/com.ibm.mq.dev.doc/q032000_.htm
You may find the following utility program (rfhutil) helpful in understanding the RFH2 header and debugging your application:
https://github.com/ibm-messaging/mq-rfhutil
Note that the variable portion of the RFH2 header uses an XML-like syntax but does not support or understand all the features of XML, so you should not attempt to include your XML payload in the variable portion of the RFH2 header.... Instead the XML document should follow the RFH2 in the message.
One last point to note is that MQ can perform codepage conversions based on the format and CCSID of the message, but this is rarely what you want with an XML document (which typically describes the character encoding of the document it's own declaration like this: <?xml version="1.0" encoding="UTF-8" standalone="no" ?>. I would therefore recommend that you set the Format field in the RFH2 to "MQFMT_NONE" so that the XML document is treated as binary data and not converted unnecessarily when the message is received by the MQ client.

Related

How to create MQRFH2 Header with "Other" (not usr area) folder with JMS

Using Spring's JmsTemplate message.setStringProperty("param", "value") one can set the value in MQRFH2.usr. How can we set values in MQRFH2.other?
I'm not a JMS guy but I do know how to do it with regular MQ/Java API.
You use the MQRFH2 class and use the setFieldValue method:
rfh2.setFieldValue("other", "SomeText", "TEST");
I cannot find where I posted my program MQTest71.java on StackOverflow but you can find a write up on my blog here.
Update 2020/01/14:
This afternoon I played around with MQ/Java programs that created various folders in an MQRFH2 message and then ran MQ/JMS programs to retrieve the messages. MQ/JMS programs simply ignore all folders outside of 'mcd', 'jms' and 'usr'.
Therefore, you need to put the name/value properties in the 'usr' folder if you want MQ/JMS applications to access the information.
According to MQ 9.1.x>Reference>Developing applications reference>MQI applications reference>Properties specified as MQRFH2 elements>Supported MQRFH2 folders there is no other folder.
The folders <jms>, <mcd>, <mqext>, and <usr> are described in The MQRFH2 header and JMS. The <usr> folder is used to transport any JMS application-defined properties that are associated with a message. Groups are not allowed in the <usr> folder.

How to set properties for AMQ message

I am sending XML message to AMQ queue. XML has header section. I need to set child nodes of header as properties of AMQ message. I am using NodeJS stompit package.
Currently message shows only one property which is JMSXDeliveryCount.
The stompit documentation has an example where the destination and content-type headers are set when using the client.send method. You can add whatever other headers you want there.

How to publish message to IBM WebsphereMQ TOPIC using rubywmq gem

I'm trying to use rubywmq gem to publish message to a IBM MQ pub/sub topic. I do not see any direct way of publishing to topic from Ruby code.
Following is the MQ TOPIC, SUB setup MQSC:
DEFINE TOPIC(MY_TOPIC) TOPICSTR('COM/APP')
DEFINE QALIAS(MY_TOPIC_Q) TARGET(MY_TOPIC) TARGTYPE(TOPIC)
DEFINE QLOCAL(APP.RAW.INPUT)
DEFINE QLOCAL(APP.VALIDATOR.INPUT)
DEFINE QLOCAL(APP.ENRICHER.INPUT)
DEFINE QLOCAL(APP.XFORM.INPUT)
DEFINE QLOCAL(APP.LOGGER.INPUT)
DEFINE SUB(SUB.APP.RAW.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('MSG/RAW') DEST(APP.RAW.INPUT)
DEFINE SUB(SUB.APP.VALIDATOR.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('MSG/XML') DEST(APP.VALIDATOR.INPUT)
DEFINE SUB(SUB.APP.ENRICHER.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('MSG/VLD') DEST(APP.ENRICHER.INPUT)
DEFINE SUB(SUB.APP.XFORM.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('MSG/ENR') DEST(APP.XFORM.INPUT)
DEFINE SUB(SUB.APP.LOGGER.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('#') DEST(APP.LOGGER.INPUT)
I also tried publishing to alias queue for the topic with MQRFH2 header
Ruby Code:
WMQ::QueueManager.connect(:connection_name => conn_name, :channel_name => channel_name, :q_mgr_name=> queue_manager) do |qmgr|
message = WMQ::Message.new
message.data = 'Hello World'
message.headers = [
{
header_type: :rf_header_2,
xml: ['<route>COM/APP/MSG/RAW</route>']
}
]
message.descriptor[:format] = WMQ::MQFMT_STRING
qmgr.put(q_name: 'MY_TOPIC_Q', message: message )
end
And then add a SUB with selector like:
DEFINE SUB(SUB.APP.RAW.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('MSG/RAW') DEST(APP.RAW.INPUT) PSPROP(RFH2) SELECTOR('route = ''COM/APP/MSG/RAW''')
Couldn't succeed. Could anyone please point where the problem is or suggest an alternative? Thanks.
Software Version Used:
IBM WMQ Server & Client v7.5
Ruby v2.3.0
rubywmq v2.1.1
Putting a message to an alias over a topic is a method to convert point-to-point apps to pub/sub. Since the API call is PUT and not PUBLISH, there is no mechanism to add a topic string to the prefix supplied by the topic object. The messages are published to the topic string as defined in the topic object and no further. Your SUB.APP.LOGGER.INPUT subscription should be seeing the publications, but not the other ones.
There are several other issues in the posted code. The crafting of an RFH2 header suggests you are relying on docs from perhaps as early as v5.3 or v6. Unfortunately, there is no mention of which version the MQ server is at or which version client libraries are being used by Ruby.
There is also no mention of what you meant by "Couldn't succeed." Does that mean you saw zero publications, even on SUB.APP.LOGGER.INPUT pub appeared to PUT messages OK? Or the PUT returned a bad reason code? Or that you got messages on SUB.APP.LOGGER.INPUT but nowhere else?
For debugging purposes, you can use MQ Explorer, the amqsput sample, or any of the other supplied tools to drop a message onto the alias queue and look for output. The difference between that test and your Ruby testing should help diagnose the issue.
Please do come back and update your question with additional details if you'd like a less speculative response.
The QALIAS must point to a TOPIC object specific to the TOPICSTR you want to publish to. Example:
DEFINE TOPIC(MY_TOPIC_MSG_RAW) TOPICSTR('COM/APP/MSG/RAW')
DEFINE QALIAS(MY_TOPIC_Q) TARGET(MY_TOPIC_MSG_RAW) TARGTYPE(TOPIC)

extract the filename from MQ Message header

Iam using Websphere MQ V8.
I need to get the filename from the header in incoming message file. Is there any properties or default methods available to get it.
Sample File:
The file ame you show in the non-hex dump of your message was put there by the sending application. You should ask the sending application how it was put in there, so that you can know how to pull it out.
Alternatively, show the hex version of your message as well and we might be able to help you further. All the important stuff is not visible to us in your screen shot.
That looks like an RFH version 1 header (not RFH2) but as Morag said, we need to see a hex dump of the message. There are lots of tools to see the hex dump of the message. i.e. amqsbcg, MO71, MQ Visual Edit, etc...
From the manual:
The RFH header guidelines only allow for a single header to exist in a message. The fixed binary set of properties is followed by a variable set of name/value pairs.
strucid
version
struclength
encoding
codedcharsetid
format
flags
namevaluestring
The filename is in the "namevaluestring" section and as Morag said, you need to have a discussion with the sending application to understand the format they used.
Finally, if this is a new sending application being developed then tell the developer to NOT use RFH version 1 but rather message properties.

ANSI Message format validator

We know ANSI is the one of the standard and format for transfer the financial and billing information between organisation, in our terms application, ie integration purpose, while developing the ANSI format integrations we need some message format validator software that could be helpful to identify the segments required fields and match the segments and values between templates and actual message that we are constructing.
I have one validator for HL7 message like 7edit, like this do we have any ANSI message validator that will integrate all like ANSI, UB04 message elements.
Thanks in advance.
Your best bet might be to use open-source Java libraries and create a small app yourself.
Here are some libraries:
EDIReader http://berryworkssoftware.net/index.php?option=com_content&task=view&id=13&Itemid=27
BOTS http://bots.sourceforge.net/en/index.shtml
SMOOKS http://www.smooks.org/

Resources