mule & seda的学习一

mule:轻量级的ESB消息框架,可以和spring集成,支持seda架构。

seda:分段式事件驱动架构,可以在每个stage上施加不同的thread,来确保程序的最大吞吐量。

几个名词解释

Connectiors:支持不同协议的连接器,屏蔽有不同协议带来的复杂度

EndPoints Address:终端地址,类似于jms等消息机制

UMO:统一消息对象,在mule里面他们是一些POJO,负责解释消息,处理消息,然后再发送给下一个UMO,形成一个UMO处理链。

mule框架地址http://www.mulesoft.org/

下载下来并解压缩打开examples文件夹,里面有很多例子,最初级的例子是echo

D:/mule/mule-standalone-2.2.1/examples

1.运行echo项目,初次体验mule

执行echo.bat批处理文件,有三种选择,你可以在命令窗口下输入1,2或者3选择不同的模式1是基本模式,2是Axis模式,3是CXF模式

对应着D:/mule/mule-standalone-2.2.1/examples/echo/conf文件夹下的三个配置文件,根据你的选择加装不同的配置文件

2.自己动手写一个echo程序,代码如下

EchoService接口

package com.zxgllhh.testMule;

public interface EchoService {

    public String echo(String echo);
}

EchoComponent实现类

package com.zxgllhh.testMule.impl;

import com.zxgllhh.testMule.EchoService;

public class EchoComponent implements EchoService {

    public String echo(String echo) {
        System.out.println("Echo Component start....");
        return echo;
    }

}

加装配置文件的主动类

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

mule-config.xml配置文件

<?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"
    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">
    <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"/>
                <vm:inbound-endpoint path="echo"/>
            </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>

发布成webservice应用,有webservice驱动程序运行代码修改如下

接口

package com.zxgllhh.testMule;

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService
public interface EchoService {
    //定义返回参数节点
    @WebResult(name="responseResultByzxg")
    //定义请求参数节点
    public String echo(@WebParam(name="requestResultByzxg") String string);
}

实现类

package com.zxgllhh.testMule.impl;

import com.zxgllhh.testMule.EchoService;

public class EchoComponent implements EchoService {

    public String echo(String echo) {
        return "Hello ,"+echo;
    }

}

配置文件

<?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"
    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">
   
    <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>

    <!-- CXF下的mule配置 -->
    <model name="echoSample">
        <service name="EchoService">
            <inbound>
                <cxf:inbound-endpoint address="http://localhost:65082/services/EchoServiceUMO"
                                      serviceClass="com.zxgllhh.testMule.EchoService"/>
            </inbound>
            <component class="com.zxgllhh.testMule.impl.EchoComponent"></component>
        </service>
    </model>
   
    <!--
    <model name="firstMuleModel">
        <service name="firstModelService">
            <inbound>
                <stdio:inbound-endpoint system="IN"/>
                <vm:inbound-endpoint path="echo"/>
            </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>

对配置文件的总结

mule--description

        --model--service--inbound

                                 --outbound

                                 --component

你可能感兴趣的:(mule & seda的学习一)