`

mule & seda 学习二

    博客分类:
  • SOA
阅读更多
mule的jdbc,配置seda以及vm的初步认识

java类

package com.zxgllhh.jdbc;
import java.util.Map;
public class NumberServiceComponent {
public NumberServiceComponent(){

}
public Object process(Object vm) throws Exception{
Thread.sleep(5000l);
System.out.println();
Map map = (Map)vm;
System.out.println("NumberServiceComponent, jdbc message is "+map.get("red_one"));
System.out.println("NumberServiceComponent, this hashcode is "+this.hashCode());
return " ..... return NumberServiceComponent is : "+vm +" .....";
}
}

配置文件

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.2"
xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.2"
xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.mulesource.org/schema/mule/jdbc/2.2"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.mulesource.org/schema/mule/soap/2.2 http://www.mulesource.org/schema/mule/soap/2.2/mule-soap.xsd
http://www.mulesource.org/schema/mule/cxf/2.2 http://www.mulesource.org/schema/mule/cxf/2.2/mule-cxf.xsd
http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd
http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.mulesource.org/schema/mule/jdbc/2.2 http://www.mulesource.org/schema/mule/jdbc/2.2/mule-jdbc.xsd">

<description>
this is a description, to be expert or not to be is not a question.

To invoke the EchoUMO hit the following URL -
http://localhost:65082/services/EchoServiceUMO/echo/requestResultByzxg/zxg

To view the WSDL for the EchoUMO service go to -
http://localhost:65082/services/EchoServiceUMO?wsdl
</description>

<spring:beans>
<spring:import resource="classpath:conf/applicationContext.xml" />
</spring:beans>

<configuration>
<default-threading-profile maxThreadsActive="10" maxBufferSize="10" poolExhaustedAction="WAIT"/>
<default-service-threading-profile maxThreadsActive="2" maxBufferSize="2" poolExhaustedAction="WAIT"/>
</configuration>

<jdbc:connector name="jdbcConnectorActive" pollingFrequency="10" dataSource-ref="dataSource">
<jdbc:query key="selectNumber"
value="select t.red_one from win_number t where rownum between 0 and 10 " />
</jdbc:connector>

<context:property-placeholder location="email.properties,system.properties" />

<!-- CXF下的mule配置 -->

<vm:connector name="vmConnector" queueEvents="true" />

<model name="echoSample">

<service name="jdbcService">
<inbound>
<jdbc:inbound-endpoint queryKey="selectNumber" />
</inbound>
<!--
<component class="com.zxgllhh.jdbc.NumberServiceComponent" />
-->
<!-- 使用对象池技术,在系统启动时就会先创建一批对象(本配置为10个)放在对象池里,等发起调用时,系统不会创建新的对象,because the component will reused -->
<pooled-component class="com.zxgllhh.jdbc.NumberServiceComponent">
<pooling-profile exhaustedAction="WHEN_EXHAUSTED_FAIL" initialisationPolicy="INITIALISE_ALL"
maxActive="5" maxIdle="5" maxWait="5" />
</pooled-component>
<outbound>
<pass-through-router>
<stdio:outbound-endpoint system="OUT"/>
</pass-through-router>
</outbound>
</service>

<service name="EchoService">
<inbound>
<cxf:inbound-endpoint address="http://localhost:65082/services/EchoServiceUMO"
serviceClass="com.zxgllhh.testMule.EchoService"/>
</inbound>
<!-- 每次调用mule都会创建一个新的对象 -->
<component class="com.zxgllhh.testMule.impl.EchoComponent" />

<!-- 配置一个vm Transport -->
<outbound>
<pass-through-router>
<vm:outbound-endpoint address="vm://orders" />
</pass-through-router>
</outbound>
</service>

<!-- 接收vm传来的消息并做处理 -->
<service name="serviceName">
<inbound>
<vm:inbound-endpoint address="vm://orders" />
</inbound>
<!--
<component class="${vm-component}" />
-->
<!-- 使用对象池技术,在系统启动时就会先创建一批对象(本配置为3个)放在对象池里,等发起调用时,系统不会创建新的对象,because the component will reused -->
<pooled-component class="${vm-component}">
<pooling-profile exhaustedAction="WHEN_EXHAUSTED_FAIL" initialisationPolicy="INITIALISE_ALL"
maxActive="1" maxIdle="2" maxWait="3" />
</pooled-component>

<outbound>
<pass-through-router>
<stdio:outbound-endpoint system="OUT"/>
</pass-through-router>
</outbound>
</service>
</model>
<!--
<description>
this is a description, to be expert or not to be is not a question.
</description>

<model name="firstMuleModel">
<service name="firstModelService">
<inbound>
<stdio:inbound-endpoint system="IN"/>
</inbound>
<component class="com.zxgllhh.testMule.impl.EchoComponent"></component>
<outbound>
<pass-through-router>
<stdio:outbound-endpoint system="OUT"/>
</pass-through-router>
</outbound>
</service>
</model>
-->
</mule>
spring配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License, Version
2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0 Unless required by
applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the
License.
-->
<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
>
<!--
<import
resource="classpath:conf/framework/spring.framework.ibatis.xml"></import>

<import
resource="classpath:conf/framework/__global/spring.framework.transaction.xml"></import>
-->

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="shutdown">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl" />
<property name="acquireIncrement" value="5" />
<property name="initialPoolSize" value="10" />
<property name="maxPoolSize" value="50" />
<property name="minPoolSize" value="10" />
<property name="properties">
<props>
<prop key="user">ssq</prop>
<prop key="password">ssq</prop>
</props>
</property>
</bean>

<!--
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:conf/sqlmap.config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>

<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>

<bean id="SpringContextUtils" class="com.tydic.framework.utils.spring.SpringContextUtils" />
-->
</beans>
运行类

package com.zxgllhh.run;

import org.mule.api.MuleContext;
import org.mule.api.context.MuleContextFactory;
import org.mule.config.spring.SpringXmlConfigurationBuilder;
import org.mule.context.DefaultMuleContextFactory;

public class EagleMuleMain {
public static void main(String[] args) throws Exception{
try {
String configFile = "com/zxgllhh/run/mule-config.xml";
String[] configFileArr = new String[] { configFile };
MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
MuleContext context = muleContextFactory
.createMuleContext(new SpringXmlConfigurationBuilder(
configFileArr));
context.start();
} catch (Exception t) {
t.printStackTrace();
}
}
}

<service name="jdbcService">
<inbound>
<jdbc:inbound-endpoint queryKey="selectNumber" />
</inbound>
<!--
<component class="com.zxgllhh.jdbc.NumberServiceComponent" />
-->
<!-- 使用对象池技术,在系统启动时就会先创建一批对象(本配置为10个)放在对象池里,等发起调用时,系统不会创建新的对象,because the component will reused -->
<pooled-component class="com.zxgllhh.jdbc.NumberServiceComponent">
<pooling-profile exhaustedAction="WHEN_EXHAUSTED_FAIL" initialisationPolicy="INITIALISE_ALL"
maxActive="5" maxIdle="5" maxWait="5" />
</pooled-component>
<outbound>
<pass-through-router>
<vm:outbound-endpoint address="vm://orders" />
</pass-through-router>
</outbound>
</service>

一个名为jdbcService的service组件从selectNumber得到数据(这个数据为map格式的colum/value)处理过后,还可以把消息发送到

vm://orders上等待下一步的执行。这就是分段式事件驱动架构。

package com.zxgllhh.jdbc;

import java.util.Map;

public class NumberServiceComponent {

public NumberServiceComponent(){

}

public Object process(Object vm) throws Exception{
Thread.sleep(5000l);
System.out.println();
Map map = (Map)vm;
System.out.println("NumberServiceComponent, jdbc message is "+map.get("red_one"));
System.out.println("NumberServiceComponent, this hashcode is "+this.hashCode());
return map;
}
}

package com.zxgllhh.vm;

public class VMComponent {

public VMComponent(){
System.out.println("init VMComponent...");
}

public Object process(Object vm){
System.out.println("VMComponent, vm message is "+vm);
System.out.println("VMComponent, this hashcode is "+this.hashCode());
return "vm : "+vm;
}
}


分享到:
评论

相关推荐

    MuleEsb开源框架简介.pdf

    7. 使用基于 SEDA 处理模型的高度可伸缩的企业服务器。 8. 强大的基于 EIP 模式的事件路由机制等。 Mule ESB 的整体结构图: Mule 通过 Transports/Connectors 与外围的异构系统连接,提供 Routing(路由)、...

    mule(java)开发简介

    #### 二、Mule 主要特性 1. **基于 J2EE 1.4 的企业消息总线 (ESB) 和消息代理:** - 提供了一个强大的平台用于构建企业级的应用程序和服务集成解决方案。 2. **可插入的连接性:** - 支持多种协议和技术,如 ...

    MuleEsb开源框架简介

    无论是对于初学者还是经验丰富的开发者,Mule ESB都提供了广泛的学习资源,如《Mule in Action》书籍、官方文档以及DZone Refcardz等,帮助用户深入了解并掌握这一强大的集成框架。随着技术的不断进步,Mule ESB持续...

    mule esb 的简单介绍

    7. **基于SEDA(Staged Event-Driven Architecture)的处理模型**:这使得Mule能够处理高并发和大规模的事务,确保系统的可伸缩性。 8. **基于EIP(Enterprise Integration Patterns)的事件路由**:Mule ESB利用...

    MULE开发文档

    MULE的核心是一个基于SEDA的服务容器,该容器管理被称为通用消息对象(Universal MessageObjects /UMO)的服务对象,而这些对象都是POJO。 MULE的架构主要由三个部分组成:Mule Manager、Model和UMO Components。...

    应用集成开源框架MULE的源代码

    Mule 的核心是一个基于SEDA的服务容器,该容器管理被称为通用消息对象(Universal Message Objects /UMO)的服务对象,而这些对象都是POJO。所有UMO和其他应用之间的通信都是通过消息端点(message endpoint)来进行...

    MULE IN ACTION

    Mule采用了SEDA(Staged Event-Driven Architecture)模型,这是一种事件驱动的架构模式,通过将应用程序分成多个阶段来实现高吞吐量和可伸缩性。 8. 强大的基于EIP模式的事件路由机制: 事件驱动模式(EIP)允许...

    Mule是一个企业服务总线(ESB)消息框架

    7.使用基于SEDA处理模型的高度可伸缩的企业服务器. 8.强大的基于EIP模式的事件路由机制等. Mule发布最新版本1.1,这个发布包括集成了JBI,对 BPEL的支持,还增加一些新的传输器(transport)Quartz,FTP,RMI与EJB等。

    ESB解决方案-mule分享.docx

    目前市场上有多种 ESB 产品,包括 Oracle 的商业 ESB 产品、Progress 的商业 ESB 产品、TIBCO 的商业 ESB 产品、Mule 的开源 ESB 框架、WSO2 的开源 ESB 框架等。这些产品都提供了基本的 ESB 功能,包括消息传递、...

Global site tag (gtag.js) - Google Analytics