`
li-yuan
  • 浏览: 66377 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

骑骡试验,用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 代码
 
  1. <outbound-router>  
  2.         <router  className="org.mule.routing.outbound.OutboundPassThroughRouter">  
  3.                <endpoint address="stream://System.out"/>  
  4.         </router>  
  5.  </outbound-router>  
<outbound-router>
接着我们修改hello-config.xml把处理结果发送给Echo,这里要特别注意一个问题因为要启动两个Mule实例,就必须让两个实例的Mule Admin监听不同的端口,默认情况下Mule Admin都是监听60504端口,echo已经监听了60504端口了,所以我们让hello监听60506端口,这就需要在hello-config.xml增加一个配置来指定Mule Admin服务的url:
<mule-environment-properties serverurl="tcp://localhost:60506">
xml 代码
 
  1. <mule-environment-properties serverUrl="tcp://localhost:60506"/>  

修改ChitChatUMO descriptor的outbound-router把System.out endpoint改成Web Service的endpoint。具体修改如下:
<mule-descriptor implementation="org.mule.components.simple.BridgeComponent" name="ChitChatUMO"></mule-descriptor></mule-environment-properties><interceptor name="default">
xml 代码
 
  1. <mule-descriptor name="ChitChatUMO" implementation="org.mule.components.simple.BridgeComponent">  
  2.             <inbound-router>  
  3.                 <endpoint address="vm://chitchatter" transformers="NameStringToChatString"/>  
  4.             </inbound-router>  
  5.             <outbound-router>  
  6.                 <router className="org.mule.routing.outbound.OutboundPassThroughRouter">  
  7.                     <!--endpoint address="stream://System.out" transformers="ChatStringToString" /-->  
  8.                     <endpoint address="axis:http://localhost:65081/services/EchoUMO?method=echo" transformers="ChatStringToString">  
  9.                         <properties>  
  10.                             <property name="soapAction" value="${methodNamespace}${method}"/>  
  11.                             <map name="soapMethods">  
  12.                                 <list name="qname{echo:http://simple.components.mule.org}">  
  13.                                     <entry value="echoRequest;string;in"/>  
  14.                                     <entry value="echoResponse;string;out"/>  
  15.                                 </list>  
  16.                             </map>  
  17.                         </properties>  
  18.                     </endpoint>  
  19.                 </router>  
  20.             </outbound-router>  
  21.             <interceptor name="default"/>  
  22.         </mule-descriptor>  
    </interceptor>
都修改好了,启动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文件
<outbound-router></outbound-router>
xml 代码
 
  1. <outbound-router>  
  2.     <router className="org.mule.routing.outbound.OutboundPassThroughRouter">  
  3.         <endpoint address="tcp://localhost:7979"/>  
  4.     </router>  
  5. </outbound-router>  

echo-config2.xml文件
<inbound-router><endpoint address="stream://System.in"><endpoint address="vm://echo">
xml 代码
 
  1. <inbound-router>  
  2.      <endpoint address="tcp://localhost:7979"/>  
  3.      <endpoint address="stream://System.in"/>  
  4.      <endpoint address="vm://echo" />                 
  5. </inbound-router>  

现在分别启动echo1和echo2,在echo1的标准输入中输入xx,在echo2的控制台上可以看到输出xx。
tcp协议是我比较关心的,光靠这个试验还是有很多不懂的例如tcp的连接是想http那样发送一个请求就关闭一次还是一直保持连接,只有等有空再自己写个demo试试。
Mule如果能有一个像BizTalk那样的图形化开发工具和监控工具那就更好了,相信不久就会有这样的工具被开发出来,数据格式转化的支持好像也没有太多可用的现成组件这点要像有些国产的集成平台就好了。
</endpoint></inbound-router></outbound-router>
分享到:
评论
1 楼 waitmannee 2007-12-31  
現在有了這樣的工具了啊,我們公司開發的IDBUS,就是用界面配置xml文件,支持絕大部分協議
http://www.idsignet.com/web/portal/products/idbus看看吧,不過不免費的哦

相关推荐

Global site tag (gtag.js) - Google Analytics