JavaCompute 节点创建新消息
调用 MbMessage 的缺省构造函数以创建空白消息
MbMessage outMessage = new MbMessage();
从入局消息复制这些头
copyMessageHeaders(inMessage, outMessage);
创建新的消息体
首先,添加顶级解析器元素
对于 XML
MbElement outRoot = outMessage.getRootElement();
MbElement outBody = outRoot.createElementAsLastChild("XMLNSC");
然后,可以使用 createElement 方法和代理 XPath 实现的扩展语法构建该消息的其余部分。
文档与java操作。
<document>
<chapter title='Introduction'>
某些文本。
</chapter>
</document>
示例程序。
import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.*;
public class pub_sub_flow_JavaCompute extends MbJavaComputeNode {
public void evaluate(MbMessageAssembly inAssembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");
MbMessage inMessage = inAssembly.getMessage();
// create new message
MbMessage outMessage = new MbMessage(inMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly,
outMessage);
try {
// ----------------------------------------------------------
/**
<document>
<chapter title='Introduction'>
某些文本。
</chapter>
</document>
*/
// get the chapter
MbElement root = inAssembly.getMessage().getRootElement();
MbElement chapter = root.getLastChild().getFirstChild().getFirstChild();
// Add user code below
// get the LocalEnvironment.
inAssembly.getLocalEnvironment();
// get the GlobalEnvironment.
inAssembly.getGlobalEnvironment();
// get the message from the MbMessageAssembly.;
// first too check the MbMessageAssembly.
MbMessage msg = inAssembly.getMessage();
// get the root. it is the root.
MbElement eleroot = msg.getRootElement();
// get the attribute. it is the first child;
MbElement eleatt = eleroot.getFirstChild();
// get the MQMD.
MbElement elemqmd = eleroot.getNextSibling();
// get the xml. it is the message.
MbElement msgbody = eleroot.getLastChild();
msgbody = elemqmd.getNextSibling();
// End of user code
// ----------------------------------------------------------
// The following should only be changed
// if not propagating message to the 'out' terminal
System.out.println("AAAAAA");
out.propagate(outAssembly);