首页 > 编程语言 >WebSphere Message Broker -JavaCompute组件的使用

WebSphere Message Broker -JavaCompute组件的使用

时间:2023-04-24 16:33:03浏览次数:38  
标签:MbException WebSphere Broker private JavaCompute MbElement nodeset expression th


 

 IBM WebSphere Message Broker JavaCompute节点的使用.

 

import java.util.List;

import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.*;


public class Sub_FFN_JavaCompute extends MbJavaComputeNode {


	private final ArticleCreator articleCreator;
	private final StatementCreator statementCreator;
	private final SaleListCreator saleListCreator;
	
	public Sub_FFN_JavaCompute() throws MbException
	{
		// instantiate the output tree creation objects

		saleListCreator = new SaleListCreator();
		statementCreator = new StatementCreator();
		articleCreator = new ArticleCreator();
	}

	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 {			
			
			
			MbElement root = outMessage.getRootElement();
			MbElement document = root.getLastChild().getFirstChild();
			MbElement chapter2 = document.createElementAsLastChild(MbElement.TYPE_NAME,"Chapter",null);

			// add title attribute
			MbElement title2 = chapter2.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,
			"title", "Message Flows");
			
			document.createElementAsLastChild(MbElement.TYPE_NAME,"NAME","ZhouHaiTao");
			out.propagate(outAssembly);

		} finally {
			// clear the outMessage
			outMessage.clearMessage();
		}
	}

	//复制头信息到outMessage中;
	public void copyMessageHeaders(MbMessage inMessage, MbMessage outMessage)
	throws MbException 
	{
		MbElement outRoot = outMessage.getRootElement();

		// iterate though the headers starting with the first child of the root element
		MbElement header = inMessage.getRootElement().getFirstChild();
		while (header != null && header.getNextSibling() != null) // stop before the last child (body)
		{
			// copy the header and add it to the out message
			outRoot.addAsLastChild(header.copy());
			// move along to next header
			header = header.getNextSibling();
		}
	}


	/**
	 * Iterates over the incoming message's SaleList elements and builds the output
	 * message's SaleList
	 * 在入报文的遍历SaleList元素并建立输出讯息。
	 * 
	 */
	private final class SaleListCreator extends XPathOperation 
	{
		private SaleListCreator() throws MbException 
		{
			super("/SaleEnvelope/SaleList"); // expression evaluated on the incoming message
		}

		/**
		 * Called once for each SaleList element
		 */
		@SuppressWarnings("unchecked")
		protected void forEachElement(MbElement saleList) throws MbException
		{
			List <MbElement> nodeset = (List <MbElement>)getOutputElement().evaluateXPath("/?SaleEnvelope/?$SaleList");
			MbElement outSaleList = nodeset.get(0);

			// create the statements for each SaleList
			statementCreator.setOutputElement(outSaleList);
			statementCreator.evaluate(saleList);
		}
	}


	private final class ArticleCreator extends XPathOperation {
		
		private ArticleCreator() throws MbException 
		{
			super("Item"); // expression evaluated on the incoming Invoice sub-tree
		}


		public ArticleCreator(String expression) throws MbException {
			super(expression);
			// TODO 自动生成的构造函数存根
		}

		//遍历元素;
		@Override
		protected void forEachElement(MbElement element) throws MbException {
			// TODO 自动生成的方法存根

		}

	}

	/**
	 * Iterates over the incoming message's Invoice elements and builds the output
	 * message's Statement sub-tree
	 * 遍历的发票在入报文元素并建立输出;
	 */
	private final class StatementCreator extends XPathOperation 
	{
		private final MbXPath setCustomer = new MbXPath(
				"?$Statement[?@Type[set-value('Monthly')]]" +
				"           [?@Style[set-value('Full')]]" +
				"           [?Customer[?Initials[set-value(concat($invoice/Initial[1], $invoice/Initial[2]))]]" +
				"                     [?Name[set-value($invoice/Surname)]]" +
				"                     [?Balance[set-value($invoice/Balance)]]]" +
		"           /?Purchases");

		private StatementCreator() throws MbException 
		{
			super("Invoice"); // expression evaluated on the incoming SaleList sub-tree
		}

		/**
		 * Called once for each Invoice element
		 */
		@SuppressWarnings("unchecked")
		protected void forEachElement(MbElement invoice) throws MbException
		{
			MbElement outSaleList = getOutputElement();

			setCustomer.assignVariable("invoice", invoice);
			List <MbElement> nodeset = (List <MbElement>)outSaleList.evaluateXPath(setCustomer);
			MbElement purchases = nodeset.get(0);

			// Now create the articles for each invoice
			articleCreator.setOutputElement(purchases);
			articleCreator.evaluate(invoice);
		}
	}

	/**
	 * XPathOperation is an abstract helper class allowing a method to be repeatedly applied to 
	 * results of an XPath expression.  The user can optionally access the output message tree
	 * allowing message transformations to be defined based on XPath evaluations of the input
	 * tree.
	 * 是一种抽象的XPathOperation帮助类允许一个方法反复应用到,
	 * 的节点。用户可以选择性地访问输出消息树,
	 * 许信息转换的被定义基于0评估输入的树
	 */
	abstract class XPathOperation
	{
		private MbXPath xpath = null;
		private MbElement outputElement = null;

		/**
		 * Constructor taking the XPath expression to evaluate.  The expression must evaluate to 
		 * a nodeset.
		 * 通过构造方法,expression 参数值生成一个xpath路径;
		 * 
		 */
		public XPathOperation(String expression) throws MbException
		{
			xpath = new MbXPath(expression);
		}

		/**
		 * Must be called prior to the evaluate method if the user wishes to work with the output
		 * tree (eg for message transformation).
		 * 
		 */
		public void setOutputElement(MbElement out)
		{
			outputElement = out;
		}

		/**
		 * Allows the user to access the output tree in the forEachElement() method
		 */
		public MbElement getOutputElement()
		{
			return outputElement;
		}

		/** 
		 * Can be overridden by the user to do initialisation processing before iterating over the
		 * XPath nodeset results
		 */
		protected void before() throws MbException { }

		/**
		 * This gets called once for each element in the XPath nodeset results. The current element
		 * is passed in as the only argument.  This method is abstract and must be implemented
		 * in the derived class.
		 * 这将被调用一次为每个元素在0 nodeset结果。当前元素,
		 * 通过是作为唯一的论点。该方法是抽象的,必须执行
		 * 在派生类。
		 */
		protected abstract void forEachElement(MbElement element) throws MbException;

		/** 
		 * Can be overridden by the user to do post-processing after iterating over the
		 * XPath nodeset results
		 */
		protected void after() throws MbException { }

		/**
		 * Called by the user to iterate over the XPath nodeset.
		 *被称为由用户自行遍历的nodeset 0。
		 * @param element The context element to which the XPath expression will be applied.
		 */
		@SuppressWarnings("unchecked")
		public void evaluate(MbElement element) throws MbException
		{
			//根据xpath获得一个结果; 
			Object result = element.evaluateXPath(xpath);
			//如果result不是一个List实例;则return;
			if(!(result instanceof List))
			{
				// error
				return;
			}

			before();

			//强制转换成List<MbElement>List集合;
			List<MbElement> nodeset = (List<MbElement>)result;

			for(MbElement node : nodeset)
			{
				//循环遍历node节点元素; 
				forEachElement(node);
			}

			after();
		}

	}

}


标签:MbException,WebSphere,Broker,private,JavaCompute,MbElement,nodeset,expression,th
From: https://blog.51cto.com/u_16085616/6221430

相关文章

  • BIP2087E: Broker BrokerDemo was unable to process the internal configuration mes
    今天部署的时候,.出现下面这个错误,BIP4041E:执行组'默认'发现一个无效的配置信息。BIP2210E:无效的配置信息:属性名称'allowQueryWSDL'不为目标对象的有效'Main.TestMessageFlows。' Beginrunningtask[Deploying[BrokerDemo.bar]toexecutiongroup[default]]BIP2087E:Broker......
  • EMQX vs NanoMQ | 2023 MQTT Broker 对比
    引言EMQX和NanoMQ都是由全球领先的开源物联网数据基础设施软件供应商EMQ开发的开源MQTTBroker。EMQX是一个高度可扩展的大规模分布式MQTTBroker,能够将百万级的物联网设备连接到云端。NanoMQ则是专为物联网边缘场景设计的轻量级Broker。本文中我们将对EMQX和NanoMQ......
  • Websphere运维
    查看IHS的cert有效期:/opt/IBM/IBMIHS90/bin/gskcapicmd-cert-details-dbcertname.kdb-stashed-labelcertname查看MQcert有效期:echo""|openssls_client-connectlocalhost:1415>/tmp/getCert.logopensslx509-in/tmp/getCert.log-enddate-noout|......
  • broker启动过程源码分析
    1broker源码入口2创建broker控制器2.1设置netty发送和接收buf大小,默认为128k2.2加载命令行的参数信息2.3生成broker配置对象......
  • TIdHTTPWebBrokerBridge替换成mormot底层
    目前使用案例是git开源项目horse改动思路大概为http请求被WebBrokerDispatch函数转发到了WebModule中进行后续处理。替换如下单元源码即可将horse项目的indy底层改成morm......
  • java——spring boot集成kafka——broker、主题、分区、副本——概念理解
    一、代理商Broker 在之前我们已经为大家介绍了生产者向消息队列中投递消息,消费者从消息队列中拉取数据。 在kafka消息队列中有一个非常重要的概念就是代理Broker,大家......
  • mq超时异常org.apache.rocketmq.client.exception.MQBrokerException: CODE: 2 DESC:
       mq生产环境正常生产和消费都挺稳定的,99.999%应该都没问题的,比较稳定。今天刚好碰到过一例因为写超时导致异常问题。   2023-02-2321:19:58.449TID:8b......
  • Security Bulletin: IBM WebSphere Application Server is vulnerable to a remote co
    Skiptocontent  Support  DownloadsDocumentationForumsCasesMonitoringManagesupportaccount  IBMSupport ......
  • 04-KafkaBroker
    1.工作流程1.1Zk存储的信息1.2总体工作流程step1~6:step7~11:模拟broker上下线,Zk中的数据变化:(1)查看/kafka/brokers/ids路径上的节点[zk:localhost:2181(......
  • 合理安排kafka的broker、partition、consumer数量
    broker的数量最好大于等于partition数量一个partition最好对应一个硬盘,这样能最大限度发挥顺序写的优势。一个broker如果对应多个partition,需要随机分发,顺序IO会退化成随......