Accessing the MQRFH2 header by using a JavaCompute node
You can use a JavaCompute node to add an MQRFH2 header to an outgoing message.
About this task
When you construct MQRFH2 headers
in a JavaCompute node,
two types of field exist:
- Fields in the MQRFH2 header structure (for example, Format and NameValueCCSID)
- Fields in the MQRFH2 NameValue buffer (for example mcd and psc)
The following code adds an MQRFH2 header to an outgoing message that is to be used to make a
subscription request:
public void addRfh2(MbMessage msg) throws MbException
{
MbElement root = msg.getRootElement();
MbElement body = root.getLastChild();
// insert new header before the message body
MbElement rfh2 = body.createElementBefore("MQHRF2");
rfh2.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "Version", new Integer(2));
rfh2.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "Format", "MQSTR");
rfh2.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "NameValueCCSID", new Integer(1208));
MbElement psc = rfh2.createElementAsFirstChild(MbElement.TYPE_NAME, "psc", null);
psc.createElementAsFirstChild(MbElement.TYPE_NAME, "Topic", "department");
psc.createElementAsFirstChild(MbElement.TYPE_NAME, "QMgrName", "QM1");
psc.createElementAsFirstChild(MbElement.TYPE_NAME, "QName", "PUBOUT");
psc.createElementAsFirstChild(MbElement.TYPE_NAME, "RegOpt", "PersAsPub");
MbXPath xp = new MbXPath("/MQMD/Format" + "[set-value(´MQHRF2´)]", root);
root.evaluateXPath(xp);
}
In this example, the MQHRF2
parameter is
the parser class name, which is different from the parser element
name (MQRFH2). For a list of the parsers, root element names, and
class names for different headers, see Available parsers.