MB与MQ操作相关

本文档详细介绍了如何在IBM WebSphere Message Broker中使用JavaCompute节点进行消息处理,包括创建新消息、复制消息头、创建和访问XML元素、更新Local和Global Environment,以及传播消息到不同终端。示例代码展示了如何操作消息树,如添加XML元素、复制MQMD和MQRFH2头等。
摘要由CSDN通过智能技术生成

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);

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值