mule 3 入门案例

转载请标明出处!~

最近想学习mule,打算从成功运行第一个例子开始。mule最新版本是mule-standalone-3.0.0,而网上很多安装入门的例子都是以前的版本,在配置xml时与以前版本不同,自己只好网上了解资料。
1.用Myeclipse 8.5在线安装插件mule:mule-standalone-3.0.0.zip版本。
更新链接: http://dist.muleforge.org/mule-ide/updates/3.4/

2.下载下载Mule 3.0.0: http://www.mulesoft.org/download-mule-esb-community-edition
并解压到某一工作目录如:D:\software\mule

3.添加骡子安装目录和选择默认的分布使用与骡子项目
Windows ->Preferences->mule->add->选择刚才解压的工作目录D:\software\mule,然后点击“OK”

4.结合网上有关例子:开发第一个Mule项目——Hello World
总体结构如:



5.创建接口
Java代码 收藏代码
  1. packagecom.mule.demo;
  2. publicinterfaceHello{
  3. publicStringhello(Stringname);
  4. }
package com.mule.demo;

public interface Hello {
	public String hello(String name);
}


5.创建实现类
Java代码 收藏代码
  1. packagecom.mule.demo;
  2. publicclassHelloImplimplementsHello{
  3. @Override
  4. publicStringhello(Stringname){
  5. //TODOAuto-generatedmethodstub
  6. returnname;
  7. }
  8. }
package com.mule.demo;

public class HelloImpl implements Hello {

	@Override
	public String hello(String name) {
		// TODO Auto-generated method stub
		return name;
	}

}


6.编写配置文件
在项目目录下创建conf文件夹,并创建文件:hello-config.xml。当然,你也可以从mule的例子中复制一个配置文件到此,mule 3.0与之前版本的配置不同,要做适当的修改。要想实现控制台输入信息,刚要配置链接stdio,红色部分。下面的本例子的配置:
Java代码 收藏代码
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <mulexmlns="http://www.mulesoft.org/schema/mule/core"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:spring="http://www.springframework.org/schema/beans"
  5. xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
  6. xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"
  7. xsi:schemaLocation="
  8. http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  9. http://www.mulesoft.org/schema/mule/corehttp://www.mulesoft.org/schema/mule/core/3.0/mule.xsd
  10. http://www.mulesoft.org/schema/mule/cxfhttp://www.mulesoft.org/schema/mule/cxf/3.0/mule-cxf.xsd
  11. http://www.mulesoft.org/schema/mule/stdiohttp://www.mulesoft.org/schema/mule/stdio/3.0/mule-stdio.xsd"
  12. >
  13. <!--
  14. Thesystemstreamconnectorisusedtosendandreceiveinformationviathe
  15. System.inandSystem.out.Notethisconnectorisonlyreallyusefulfortesting
  16. purposes.
  17. promptMessage-iswhatiswrittentotheconsole
  18. messageDelayTime-isthetimeinmillisecondsbeforetheuserispromptedagain.
  19. Thesepropertiesaresetasbeanpropertiesontheconnector.
  20. -->
  21. <stdio:connectorname="SystemStreamConnector"
  22. promptMessage="Pleaseenteryoutname:"
  23. messageDelayTime="1000"/>
  24. <!--
  25. TheMulemodelinitialisesandmanagesyourUMOcomponents
  26. -->
  27. <modelname="HelloSample">
  28. <!--
  29. AMuleservicedefinesallthenecessaryinformationabouthowyourcomponentswill
  30. interactwiththeframework,othercomponentsinthesystemandexternalsources.
  31. PleaserefertotheConfigurationGuideforafulldescriptionofalltheparameters.
  32. -->
  33. <servicename="HelloUMO">
  34. <inbound>
  35. <stdio:inbound-endpointsystem="IN"/>
  36. </inbound>
  37. <componentclass="com.mule.demo.HelloImpl"/>
  38. <outbound>
  39. <pass-through-router>
  40. <stdio:outbound-endpointsystem="OUT"/>
  41. </pass-through-router>
  42. </outbound>
  43. </service>
  44. </model>
  45. </mule>
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:spring="http://www.springframework.org/schema/beans"
       xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
       xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"
     xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd
       http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/3.0/mule-cxf.xsd
       http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.0/mule-stdio.xsd"  
       >

<!--   
        The system stream connector is used to send and receive information via the   
        System.in and System.out. Note this connector is only really useful for testing   
        purposes.   
        promptMessage - is what is written to the console   
        messageDelayTime - is the time in milliseconds before the user is prompted again.   
        These properties are set as bean properties on the connector.   
    --> 
    
    <stdio:connector name="SystemStreamConnector"  
        promptMessage="Please enter yout name: "  
        messageDelayTime="1000"/>  
    <!--  
        The Mule model initialises and manages your UMO components  
    --> 
    <model name="HelloSample">  
        <!--   
            A Mule service defines all the necessary information about how your components will   
            interact with the framework, other components in the system and external sources.   
            Please refer to the Configuration Guide for a full description of all the parameters.   
        -->  
        <service name="HelloUMO">  
            <inbound>  
                <stdio:inbound-endpoint system="IN" /> 
            </inbound>             
            <component class="com.mule.demo.HelloImpl"/>  
  
            <outbound>  
                <pass-through-router>  
                    <stdio:outbound-endpoint system="OUT" />  
                </pass-through-router>  
            </outbound>  
        </service>        
    </model> 
</mule>


7.运行例子测试
右击hello-config.xml->run_configurations,则可看到运行效果。



来源:http://pj72021.iteye.com/blog/804956

ps:查找stdio的链接时发现mule3的例子网站:http://code.google.com/p/muleinaction/source/browse/branches/mule-3/chapter04/collection-aggregator/conf/collection-aggregator-config.xml?spec=svn479&r=479


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值