CEP 与 JMS 结合的参考文章

本文介绍了如何在OracleCEP中利用Java消息服务(JMS)适配器来发送和接收消息,包括适配器的概述、典型步骤以及配置细节。重点在于提供创建自定义转换器的方法,以定制JMS消息到事件类型的转换过程。

http://docs.oracle.com/cd/E13213_01/wlevs/docs30/create_apps/jms.html#wp1021114

Application Development Guide

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Using the Java Message Service (JMS) Adapters

This section contains information on the following subjects:

 


Overview of Using the JMS Adapters

Oracle CEP provides two JMS adapters that you can use in your event applications to send and receive messages to and from a JMS queue, respectively, without writing any Java code. In particular:

  • The inbound JMS adapter receives map messages from a JMS queue and automatically converts them into events by matching property names with a specified event type. You can optionally customize this conversion by writing your own Java class to specify exactly how you want the incoming JMS messages to be converted into one or more event types.
  • The outbound JMS adapter sends events to a JMS queue, automatically converting the event into a JMS map message by matching property names with the event type. You can optionally customize this conversion by writing your own Java class to specify exactly how you want the event types to be converted into outgoing JMS messages.

Oracle CEP supports the following two JMS providers: Oracle WebLogic JMS and TIBCO EMS JMS.

When connecting to Oracle WebLogic server, Oracle CEP uses the T3 client by default. You can use the IIOP WebLogic client by starting Oracle WebLogic Server with the -useIIOP command-line argument. This is a server-wide setting that is independent of the JMS code being used (whether it is one of the provided adapters or custom JMS code). It is not possible to mix T3 and IIOP usage within a running Oracle CEP server.

For general information about JMS, see Java Message Service on the Sun Developer Network.

 


Using JMS Adapters: Typical Steps

The following procedure describes the typical steps to use the JMS adapters provided by Oracle CEP.

Note:It assumed in this section that you have already created an Oracle CEP application along with its EPN assembly file and and component configuration files, and that you want to update the application to use an inbound or outbound JMS adatper. If you have not, refer to Overview of Creating Oracle Complex Event Processing Applications for details.
  1. Optionally create a converter Java class if you want to customize the way JMS messages are converted into event types, or vice versa in the case of the outbound JMS adapter. This step is optional because you can let Oracle CEP make the conversion based on mapping property names between JMS messages and a specified event type.

    See Creating a Custom Converter Between JMS Messages and Event Types.

  2. Update the EPN assembly file of the application by adding a <wlevs:adapter> tag for each inbound and outbound JMS adapter you want to use in your application.

    See Updating the EPN Assembly File With JMS Adapters

  3. Configure the JMS properties of the JMS adapter by updating the component configuration file.

    See Configuring the JMS Adapters.

Creating a Custom Converter Between JMS Messages and Event Types

If you want to customize the way a JMS message is converted to an event type, or vice versa, you must create your own converter bean.

The custom converter bean for an inbound JMS must implement the com.bea.wlevs.adapters.jms.api.InboundMessageConverter interface. This interface has a single method:

public List convert(Message message) throws MessageConverterException, JMSException;

The message parameter corresponds to the incoming JMS message and the return value is a List of events that will be passed on to the next stage of the event processing network.

The custom converter bean for an outbound JMS must implement the com.bea.wlevs.adapters.jms.api.OutboundMessageConverter interface. This interface has a single method:

public List<Message> convert(Session session, Object event) throws MessageConverterException, JMSException;

The parameters correspond to an event received by the outbound JMS adapter from the source node in the EPN and the return value is a List of JMS messages.

See the Javadoc for a full description of these APIs.

The following example shows the Java source of a custom converter bean that implements both InboundMessageConverter and OutboundMessageConvert; this bean can be used for both inbound and outbound JMS adapters:

package com.customer;
import com.bea.wlevs.adapters.jms.api.InboundMessageConverter;
import com.bea.wlevs.adapters.jms.api.MessageConverterException;
import com.bea.wlevs.adapters.jms.api.OutboundMessageConverter;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import java.util.ArrayList;
import java.util.List;
public class MessageConverter implements InboundMessageConverter, OutboundMessageConverter {
    public List convert(Message message) throws MessageConverterException, JMSException {
        TestEvent event = new TestEvent();
        TextMessage textMessage = (TextMessage) message;
        event.setString_1(textMessage.getText());
        List events = new ArrayList(1);
        events.add(event);
        return events;
    }
    public List<Message> convert(Session session, Object inputEvent) throws MessageConverterException, JMSException {
        TestEvent event = (TestEvent) inputEvent;
        TextMessage message = session.createTextMessage("Text message: " + event.getString_1());
        List<Message> messages = new ArrayList<Message>();
        messages.add(message);
        return messages;
    }
}

Updating the EPN Assembly File With JMS Adapters

For each JMS adapter in your event processing network, you must add a corresponding <wlevs:adapter> tag to the EPN assembly file of your application; use the provider attribute to specify whether the JMS adapter is inbound or outbound. Follow these guidelines:

  • If you are specifying an inbound JMS adapter, set the provider attribute to jms-inbound, as shown:
    <wlevs:adapter id="jmsInbound" provider="jms-inbound"/>

    The value of the id attribute, in this case jmsInbound, must match the name specified for this JMS adapter in its configuration file. The configuration file configures the JMS queue from which this inbound JMS adapter gets its messages.

    Because no converter bean is specified, Oracle CEP automaticallys converts the inbound message to the event type specified in the component configuration file by mapping property names.

  • If you are specifying an outbound JMS adapter, set the provider attribute to jms-outbound, as shown:
    <wlevs:adapter id="jmsOutbound" provider="jms-outbound"/>

    The value of the id attribute, in this case jmsOutbound, must match the name specified for this JMS adapter in its configuration file. The configuration file configures the JMS queue to which this outbound JMS adapter sends messages messages.

    Because no converter bean is specified, Oracle CEP automatically converts the incoming event types to outgoing JMS messages by mapping the property names.

  • For both inbound and outbound JMS adapters, if you have created a custom converter bean to customize the converstion between the JMS messages and event types, first use the standard <bean> Spring tag to declare it in the EPN assembly file. Then pass a reference of the bean to the JMS adapter by specifying its id using the <wlevs:instance-property> tag, with the name attribute set to converterBean, as shown:
    <bean id="myConverter"
           class="com.customer.MessageConverter"/>
    <wlevs:adapter id="jmsOutbound" provider="jms-outbound">  
      <wlevs:instance-property name="converterBean" ref="myConverter"/>
    </wlevs:adapter>

    In this case, be sure you do not specify an event type in the component configuration file because it is assumed that the custom converter bean takes care of specifying the event type.

As with any other stage in the EPN, add listeners and sources to the <wlevs:adapter> tag to integrate the JMS adapter into the event processing network. Typically, an inbound JMS adapter is the first stage in an EPN (because it receives messages) and an outbound JMS adapter would be in a later stage (because it sends messages). However, the requirements of your own Oracle CEP application define where in the network the JMS adapters fit in.

The following sample EPN assembly file shows how to configure an outbound JMS adapter. The network is simple: a custom adapter called getData receives data from some feed, converts it into an event type and passes it to myProcessor, which in turn sends the events to the jmsOutbound JMS adapter via the streamOne stream. Oracle CEP automatically converts these events to JMS messages and sends the messages to the JMS queue configured in the component configuration file associated with the jmsOutbound adapter.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd
  http://www.bea.com/ns/wlevs/spring
  http://www.bea.com/ns/wlevs/spring/spring-wlevs.xsd">
    <wlevs:event-type-repository>
        <wlevs:event-type type-name="JMSEvent">
            <wlevs:class>com.customer.JMSEvent</wlevs:class>
        </wlevs:event-type>
    </wlevs:event-type-repository>
    <!-- Custom adapter that gets data from somewhere and sends it to myProcessor -->
    <wlevs:adapter id="getData" 
                     class="com.customer.GetData">
        <wlevs:listener ref="myProcessor"/>
    </wlevs:adapter>
    <wlevs:processor id="myProcessor" />
     <!-- Stream for events flowing from myProcessor to outbound JMS adapter -->
    <wlevs:stream id="streamOne">
       <wlevs:listener ref="jmsOutbound"/>
       <wlevs:source ref="myProcessor"/>
    </wlevs:stream>
</beans>

The following sample EPN assembly file shows how to configure an inbound JMS adapter. The network is simple: the inbound JMS adapter called jmsInbound receives messages from the JMS queue configured in its component configuration file. The Spring bean myConverter converts the incoming JMS messages into event types, and then these events flow to the mySink event bean.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd
  http://www.bea.com/ns/wlevs/spring
  http://www.bea.com/ns/wlevs/spring/spring-wlevs.xsd">
    <wlevs:event-type-repository>
        <wlevs:event-type type-name="JMSEvent">
            <wlevs:class>com.customer.JMSEvent</wlevs:class>
        </wlevs:event-type>
    </wlevs:event-type-repository>
    <!-- Event bean that is an event sink -->
    <wlevs:event-bean id="mySink" 
                         class="com.customer.MySink"/>
    <!-- Inbound JMS adapter with custom converter class; adapter sends events to mySink event bean-->
   <bean id="myConverter" class="com.customer.MessageConverter"/>
   <wlevs:adapter id="jmsInbound" provider="jms-inbound">
       <wlevs:instance-property name="converterBean" ref="myConverter"/>
       <wlevs:listener ref="mySink"/>
    </wlevs:adapter>
</beans>

Configuring the JMS Adapters

You configure the JMS adapters in their respective configuration files, similar to how you configure other components in the event processing network, such as processors or streams. For general information about these configuration files, see Component Configuration Files.

The root element for configuring a JMS adapter is <jms-adapter>. The <name> child element for a particular adapter must match the id attribute of the corresponding <wlevs:adapter> tag in the EPN assembly file that declares this adapter.

The following table describes the additional child elements of <jms-adapter> you can configure for both inbound and outbound JMS adapters.

Table 4-1 Child Elements of <jms-adapter> for Inbound and Outbound Adpaters
Child Element
Description
event-type
Event type whose properties match the JMS message properties.
Specify this child element only if you want Oracle CEP to automatically perform the conversion between JMS messages and events. If you have created your own custom convert bean, then do not specify this element.
jndi-provider-url
Required. The URL of the JNDI provider.
jndi-factory
Optional. The JNDI factory name. Default value is weblogic.jndi.WLInitialContextFactory, for Oracle WebLogic Server JMS.
connection-jndi-name
Optional. The JNDI name of the JMS connection factory. Default value is weblogic.jms.ConnectionFactory, for Oracle WebLogic Server JMS.
destination-jndi-name,
destination-name
Required. Either the JNDI name, or actual name, of the JMS destination. Specify one or the other, but not both.
user
Optional. The username for the external resource.
password
Optional The password for the external resource.
encrypted-password
Optional. The encrypted password for the external resource.

The following table lists the optional child elements of <jms-adapter> you can configure for inbound JMS adapters only.

Table 4-2 Optional Child Elements for Inbound JMS Adapters
Child Element
Description
work-manager
Name of a work manager, configured in the server’s config.xml file. This name corresponds to the value of the <name> child element of the <work-manager> element in config.xml.
concurrent-consumers
Number of consumers to create.
message-selector
JMS message selector to use to filter messages.
session-ack-mode-name
Use session acknowledgement mode.
session-transacted
Boolean value that specifies whether to use transacted sessions.

The following table lists the optional child elements of <jms-adapter> you can configure for outbound JMS adapters only.

Table 4-3 Optional Child Elements for Outbound JMS Adapters
Child Element
Description
delivery-mode
Specifies whether the delivery mode: persistent (default value) or nonpersistent.

For the full schema for the configuration of JMS adapters, see the XSD Schema.

The following configuration file shows a complete example of configuring both an inbound and outbound JMS adapter.

<?xml version="1.0" encoding="UTF-8"?>
<n1:config
 xsi:schemaLocation="http://www.bea.com/ns/wlevs/config/application wlevs_application_config.xsd"
 xmlns:n1="http://www.bea.com/ns/wlevs/config/application"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <jms-adapter>
        <name>jmsInbound</name>
        <jndi-provider-url>t3://localhost:7001</jndi-provider-url>
        <destination-jndi-name>Queue1</destination-jndi-name>
        <user>weblogic</user>
        <password>weblogic</password>
        <work-manager>JettyWorkManager</work-manager>
        <concurrent-consumers>1</concurrent-consumers>
        <session-transacted>false</session-transacted>
    </jms-adapter>
    <jms-adapter>
        <name>jmsOutbound</name>
        <event-type>JMSEvent</event-type>
        <jndi-provider-url>t3://localhost:7001</jndi-provider-url>
        <destination-jndi-name>Topic1</destination-jndi-name>
        <delivery-mode>nonpersistent</delivery-mode>
    </jms-adapter>
</n1:config>

The following snippet shows how to configure an inbound JMS adapter connecting to TIBCO EMS JMS:

<jms-adapter>
  <name>myJmsAdapter</name>
  <jndi-provider-url>t3://localhost:7222</jndi-provider-url>
  <jndi-factory>com.tibco.tibjms.naming.TibjmsInitialContextFactory</jndi-factory>
  <connection-jndi-name>TibcoQueueConnectionFactory</connection-jndi-name>
  <destination-jndi-name>MyQueue</destination-jndi-name>
</jms-adapter>


【Koopman】遍历论、动态模态分解和库普曼算子谱特性的计算研究(Matlab代码实现)内容概要:本文围绕【Koopman】遍历论、动态模态分解和库普曼算子谱特性的计算研究展开,重点介绍基于Matlab的代码实现方法。文章系统阐述了遍历理论的基本概念、动态模态分解(DMD)的数学原理及其库普曼算子谱特性之间的内在联系,展示了如何通过数值计算手段分析非线性动力系统的演化行为。文中提供了完整的Matlab代码示例,涵盖数据驱动的模态分解、谱分析及可视化过程,帮助读者理解并复现相关算法。同时,文档还列举了多个相关的科研方向和技术应用场景,体现出该方法在复杂系统建模分析中的广泛适用性。; 适合人群:具备一定动力系统、线性代数数值分析基础,熟悉Matlab编程,从事控制理论、流体力学、信号处理或数据驱动建模等领域研究的研究生、博士生及科研人员。; 使用场景及目标:①深入理解库普曼算子理论及其在非线性系统分析中的应用;②掌握动态模态分解(DMD)算法的实现优化;③应用于流体动力学、气候建模、生物系统、电力系统等领域的时空模态提取预测;④支撑高水平论文复现科研项目开发。; 阅读建议:建议读者结合Matlab代码逐段调试运行,对照理论推导加深理解;推荐参考文中提及的相关研究方向拓展应用场景;鼓励在实际数据上验证算法性能,并尝试改进扩展算法功能。
本系统采用微信小程序作为前端交互界面,结合Spring BootVue.js框架实现后端服务及管理后台的构建,形成一套完整的电子商务解决方案。该系统架构支持单一商户独立运营,亦兼容多商户入驻的平台模式,具备高度的灵活性扩展性。 在技术实现上,后端以Java语言为核心,依托Spring Boot框架提供稳定的业务逻辑处理数据接口服务;管理后台采用Vue.js进行开发,实现了直观高效的操作界面;前端微信小程序则为用户提供了便捷的移动端购物体验。整套系统各模块间紧密协作,功能链路完整闭环,已通过严格测试优化,符合商业应用的标准要求。 系统设计注重业务场景的全面覆盖,不仅包含商品展示、交易流程、订单处理等核心电商功能,还集成了会员管理、营销工具、数据统计等辅助模块,能够满足不同规模商户的日常运营需求。其多店铺支持机制允许平台方对入驻商户进行统一管理,同时保障各店铺在品牌展示、商品销售及客户服务方面的独立运作空间。 该解决方案强调代码结构的规范性可维护性,遵循企业级开发标准,确保了系统的长期稳定运行后续功能迭代的可行性。整体而言,这是一套技术选型成熟、架构清晰、功能完备且可直接投入商用的电商平台系统。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值