Copying a message with a .NETCompute node
Copy an existing message using the .NETCompute node.
About this task
Transformation nodes, such as the .NETCompute node, can modify the logical tree structure that is passed through a message flow from one node to the next. This tree structure, or message assembly, contains four trees to represent the message, the environment, the local environment, and the exception list. To send data from the input terminal of the .NETCompute node to the output terminal, the class associated with the node must contain an Evaluate method that either propagates the input message assembly, or creates an output message assembly. To copy a message from the input terminal to the output terminal, propagate the whole input message assembly. The template code provided for you when you create a FilterNode class in C# propagates the message. As you can see in the following code, the inputAssembly is passed to the Propagate method:
public override void Evaluate(NBMessageAssembly inputAssembly)
{
NBOutputTerminal outTerminal = OutputTerminal("Out");
NBMessage inputMessage = inputAssembly.Message;
NBElement root = inputMessage.RootElement;
#region UserCode
// Add user code in this region to filter the message
#endregion UserCode
// Change the following if not propagating message to the 'Out' terminal
outTerminal.Propagate(inputAssembly);
}
If you plan to copy the message and then also update it in the .NETCompute node, it is better to use the CreateNode template. This template creates an output assembly. You copy the input assembly to this output assembly by adding just one line of code to the UserCode region:
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;
// Optionally copy message headers, remove if not needed
CopyMessageHeaders(inputRoot, outputRoot);
#region UserCode
// Add user code in this region to create a new output message
outputRoot.AddLastChild(inputRoot.LastChild);
#endregion UserCode
// Change the following if not propagating message to the 'Out' terminal
outTerminal.Propagate(outAssembly);
}
}
For information about the .NET classes and methods that are supported in IBM® App Connect Enterprise, see the .NET API documentation.