mule 3.0.0入门例子

  最近想学习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.创建接口 


5.创建实现类 
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,红色部分。下面的本例子的配置: 
<?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,则可看到运行效果。 




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
posted @ 2011-03-23 22:58  六不朽  阅读(3220)  评论(0编辑  收藏  举报