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. package com.mule.demo;  
  2.   
  3. public interface Hello {  
  4.     public String hello(String name);  
  5. }  
package com.mule.demo;  public interface Hello { 	public String hello(String name); } 


5.创建实现类
Java代码   收藏代码
  1. package com.mule.demo;  
  2.   
  3. public class HelloImpl implements Hello {  
  4.   
  5.     @Override  
  6.     public String hello(String name) {  
  7.         // TODO Auto-generated method stub  
  8.         return name;  
  9.     }  
  10.   
  11. }  
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. <?xml version="1.0" encoding="UTF-8"?>  
  2. <mule xmlns="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/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  9.        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd  
  10.        http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/3.0/mule-cxf.xsd  
  11.        http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.0/mule-stdio.xsd"    
  12.        >  
  13.   
  14. <!--     
  15.         The system stream connector is used to send and receive information via the     
  16.         System.in and System.out. Note this connector is only really useful for testing     
  17.         purposes.     
  18.         promptMessage - is what is written to the console     
  19.         messageDelayTime - is the time in milliseconds before the user is prompted again.     
  20.         These properties are set as bean properties on the connector.     
  21.     -->   
  22.       
  23.     <stdio:connector name="SystemStreamConnector"    
  24.         promptMessage="Please enter yout name: "    
  25.         messageDelayTime="1000"/>    
  26.     <!--    
  27.         The Mule model initialises and manages your UMO components    
  28.     -->   
  29.     <model name="HelloSample">    
  30.         <!--     
  31.             A Mule service defines all the necessary information about how your components will     
  32.             interact with the framework, other components in the system and external sources.     
  33.             Please refer to the Configuration Guide for a full description of all the parameters.     
  34.         -->    
  35.         <service name="HelloUMO">    
  36.             <inbound>    
  37.                 <stdio:inbound-endpoint system="IN" />   
  38.             </inbound>               
  39.             <component class="com.mule.demo.HelloImpl"/>    
  40.     
  41.             <outbound>    
  42.                 <pass-through-router>    
  43.                     <stdio:outbound-endpoint system="OUT" />    
  44.                 </pass-through-router>    
  45.             </outbound>    
  46.         </service>          
  47.     </model>   
  48. </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


你可能感兴趣的:(mule,3)