Accessing headers with a .NETCompute node

Use a .NETCompute node to access headers in the message assembly.

About this task

Two of the most common headers encountered in messaging scenarios are the MQMD and MQRFH2. If an input node receives an input message that includes message headers that the input node recognizes, the node invokes the correct parser for each header. Parsers are supplied for most WebSphere® MQ headers. This topic provides guidance for accessing the information in the MQMD and MQRFH2 headers that you can follow when accessing other headers that are present in your messages.

For more information about the contents of these and other WebSphere MQ headers for which IBM® Integration Bus provides a parser, see Element definitions for message parsers.

The following C# code shows how to add an MQMD header and an MQRFH2 header to your message using a .NETCompute node:
        public override void Evaluate(NBMessageAssembly inputAssembly)
        {
            NBOutputTerminal outTerminal = OutputTerminal("out");

            NBMessage inputMessage = inputAssembly.Message;

            // Create a new empty message, ensuring it is disposed after use
            using (NBMessage outputMessage = new NBMessage())
            {
                NBMessageAssembly outAssembly = new NBMessageAssembly(inputAssembly, outputMessage);
                NBElement inputRoot = inputMessage.RootElement;
                NBElement outputRoot = outputMessage.RootElement;
                
                #region UserCode
                // Add user code in this region to create a new output message
                NBElement MQMD = outputRoot.CreateLastChildUsingNewParser(NBParsers.NBHeaderParsers.MQMD.ParserName);                
                NBElement MQRFH2 = outputRoot.CreateLastChildUsingNewParser(NBParsers.NBHeaderParsers.MQRFH2.ParserName);
                #endregion UserCode

                // Change the following if not propagating message to the 'Out' terminal
                outTerminal.Propagate(outAssembly);
            }
        }