论坛首页 Java企业应用论坛

骑骡试验

浏览 2375 次
锁定老帖子 主题:骑骡试验
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-01-17  
SOA
最近在看MULE,刚好看到网上有一篇不错的文章,于是一时激发了我的“拿来主义”.与大家共勉.

这几天看了一下Mule的文档,这头骡子果然不错,可以很快上手,支持的协议也很多,完全满足我策划的一个应用。看完文档和例子,总觉得手痒痒,想做点东西试试,自己从头开始觉得搭环境比较麻烦,预算打算那现成的例子来做做试验。

一、用 Web Service 集成Echo和Hello这两个例子
    Echo是Mule User Guide里的第一个例子,主要展现了如何开发一个支持多种协议的 Mule 组件,Echo 组件有一个echo方法接收一个String再把这个String原封不动的返回,这个组件可以被配置为从标准输入接收参数也可以被配置为通过Web Service接收参数。而 Hello 主要是用来说明多个组件如何协作和如何管理事件转化,这个例子接收一个String然后在前面加上Hello再输出到标准输出。既然 Mule 是应用集成框架,那么集成这个两个例子肯定不会有什么问题。集成后的流程是Hello把处理后的结果通过SOAP协议发送给一个独立运行的Echo实例,再在Echo实例的控制台上。
    首先,我们修改Echo的配置文件echo-aixs-config.xml为EchoUMO增加一个outbound-router,把EchoUMO的返回值输出到标准输出,具体修改如下:

xml 代码
<outbound-router>  
     <router  className="org.mule.routing.outbound.OutboundPassThroughRouter"> 
<endpoint address="stream://System.out"/> 
</router>  
</outbound-router>  

接着我们修改hello-config.xml把处理结果发送给Echo,这里要特别注意一个问题因为要启动两个Mule实例,就必须让两个实例的Mule Admin监听不同的端口,默认情况下Mule Admin都是监听60504端口,echo已经监听了60504端口了,所以我们让hello监听60506端口,这就需要在hello-config.xml增加一个配置来指定Mule Admin服务的url:

xml 代码
        <mule-environment-properties serverUrl="tcp://localhost:60506"/>  

修改ChitChatUMO descriptor的outbound-router把System.out endpoint改成Web Service的endpoint。具体修改如下:

xml 代码
<mule-descriptor name="ChitChatUMO" implementation="org.mule.components.simple.BridgeComponent">  
<inbound-router>  
     <endpoint address="vm://chitchatter" transformers="NameStringToChatString"/>  
</inbound-router>  
<outbound-router>  
    <router className="org.mule.routing.outbound.OutboundPassThroughRouter">  
                 <!--endpoint address="stream://System.out" transformers="ChatStringToString" /-->  
                <endpoint address="axis:http://localhost:65081/services/EchoUMO? method=echo" transformers="ChatStringToString">  
                   <properties>  
                        <property name="soapAction" value="${methodNamespace}${method}"/>  
                         <map name="soapMethods">  
                              <list name="qname{echo:http://simple.components.mule.org}">  
                                   <entry value="echoRequest;string;in"/>  
                                   <entry value="echoResponse;string;out"/>  
                             </list>  
                        </map>  
                  </properties>  
             </endpoint>  
     </router>  
</outbound-router>  
<interceptor name="default"/>  
</mule-descriptor>  
   
都修改好了,启动echo和hello在hello控制台输入echo&hello,可以看到echo控制上输出Hello echo&hello。
第一个试验完成了,通过试验知道了启动两个mule实例需要修改Mule Admin端口,知道了调用Web Services的配置方法,虽然Stock Quote例子专门用来说明如何调用Web Services,但自己动手感觉很不一样。

二、用tcp协议串连连个echo
    拷贝echo-config.xml为echo-config1.xml修改echo-config.xml给EchoUMO增加一个tcp协议的endpoint,再拷贝echo-config.xml为echo-config2.xml把EchoUMO
的outbound-router的endpoint改为tcp协议。注意为了启动两个实例和第一试验一样要修改echo-config2.xml中Mule Admin的端口。
具体修改为:
echo-config1.xml文件

xml 代码

<outbound-router>  
          <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
               <endpoint address="tcp://localhost:7979"/>  
          </router>  
</outbound-router>  


echo-config2.xml文件

xml 代码

<inbound-router>  
           <endpoint address="tcp://localhost:7979"/>  
           <endpoint address="stream://System.in"/>  
           <endpoint address="vm://echo" />                 
</inbound-router>  

现在分别启动echo1和echo2,在echo1的标准输入中输入xx,在echo2的控制台上可以看到输出xx。
tcp协议是我比较关心的,光靠这个试验还是有很多不懂的例如tcp的连接是想http那样发送一个请求就关闭一次还是一直保持连接,只有等有空再自己写个demo试试。
   发表时间:2008-05-06  
对于我学习ESB是一个好的开始。mule的两个例子也不错!
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics