| « | November 2025 | » | | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | | | |
| 公告 |
| 本博客在此声明所有文章均为转摘,只做资料收集使用。并无其他商业用途。 |
| Blog信息 |
|
blog名称: 日志总数:210 评论数量:205 留言数量:-19 访问次数:927707 建立时间:2007年5月10日 |

| |
|
[Mule]Mule入门简介  文章收藏, 网上资源, 软件技术, 电脑与网络
李小白 发表于 2007/9/12 20:03:13 |
| Mule是一个基于ESB架构的消息平台,Mule 的核心是一个基于SEDA(Staged Event Driven Architecture)的服务容器,该容器管理被称为通用消息对象(Universal Message Objects /UMO)的服务对象,而这些对象都是POJO。所有UMO和其他应用之间的通信都是通过消息端点(message endpoint)来进行的。这些端点为众多独立的技术,比如Jms, Smtp, Jdbc, Tcp, Http, Xmpp, file等等,提供了简单和一致的接口。Mule应用程序通常是通过网络由许多Mule实例组成(实际上一个应用里面只能有一个mule实例,因为实例启动之后必须占用一个tcp端口),每一个实例是由具有一个或多个UMO组件的轻量级容器所构成,每一个UMO组件都包含有一个或多个能收发事件的端点。以上描述可以用以下图例来说明:500)this.width=500'>实际上Mule是用一个配置文件来描述以上信息的,一个典型的配置文件如下:
500)this.width=500'> < mule-descriptor name ="Error Manager" implementation ="errorManager" > 500)this.width=500'> < inbound-router > 500)this.width=500'> < endpoint address ="file://./test-data/in" 500)this.width=500'> transformers ="XMLToExceptionBean ExceptionBeanToErrorMessage" /> 500)this.width=500'> </ inbound-router > 500)this.width=500'> 500)this.width=500'> < outbound-router > 500)this.width=500'> < catch-all-strategy className ="org.mule.routing.LoggingCatchAllStrategy" /> 500)this.width=500'> 500)this.width=500'> < router className ="org.mule.routing.outbound.FilteringOutboundRouter" 500)this.width=500'> transformer ="ErrorMessageToException" > 500)this.width=500'> 500)this.width=500'> < endpoint address ="file://./test-data/exceptions" 500)this.width=500'> transformers ="ErrorMessageToExceptionBean ExceptionBeanToXML" > 500)this.width=500'> 500)this.width=500'> < properties >< property name ="outputPattern" value ="Exception-${UUID}.xml" /></ properties > 500)this.width=500'> </ endpoint > 500)this.width=500'> < filter className ="org.mule.routing.filters.PayloadTypeFilter" 500)this.width=500'> expectedType ="org.mule.MuleException" /> 500)this.width=500'> </ router > 500)this.width=500'> 500)this.width=500'> < router className ="org.mule.routing.outbound.FilteringOutboundRouter" 500)this.width=500'> transformer ="ErrorMessageToException" > 500)this.width=500'> 500)this.width=500'> < endpoint address ="smtp://?address=${email.toAddress}" 500)this.width=500'> transformers ="ErrorMessageToExceptionBean ExceptionBeanToXML StringToEmailMessage" > 500)this.width=500'> < properties > 500)this.width=500'> < property name ="fromAddress" value ="${email.fromAddress}" /> 500)this.width=500'> < property name ="subject" value ="${email.subject}" /> 500)this.width=500'> </ properties > 500)this.width=500'> </ endpoint > 500)this.width=500'> 500)this.width=500'> < filter className ="org.mule.routing.filters.PayloadTypeFilter" 500)this.width=500'> expectedType ="org.mule.umo.lifecycle.FatalException" /> 500)this.width=500'> </ router > 500)this.width=500'> 500)this.width=500'> < router className ="org.mule.routing.outbound.FilteringOutboundRouter" 500)this.width=500'> transformer ="ErrorMessageToException" > 500)this.width=500'> 500)this.width=500'> < endpoint address ="jms://exception.queue" 500)this.width=500'> transformers ="ErrorMessageToExceptionBean ExceptionBeanToXML ObjectToJMSMessage" /> 500)this.width=500'> 500)this.width=500'> < filter className ="org.mule.routing.filters.PayloadTypeFilter" 500)this.width=500'> expectedType ="org.mule.samples.errorhandler.exceptions.BusinessException" /> 500)this.width=500'> </ router > 500)this.width=500'> </ outbound-router > 500)this.width=500'> 500)this.width=500'> < interceptor name ="default" /> 500)this.width=500'> </ mule-descriptor > 500)this.width=500'> 500)this.width=500'> < mule-descriptor name ="Business Error Manager" implementation ="businessErrorManager" > 500)this.width=500'> < inbound-router > 500)this.width=500'> < endpoint address ="jms://exception.queue" 500)this.width=500'> transformers ="JMSMessageToObject XMLToExceptionBean ExceptionBeanToErrorMessage" /> 500)this.width=500'> </ inbound-router > 500)this.width=500'> </ mule-descriptor >
以上是摘取官方网站上提供的一个叫errorhandler的例子里配置文件的一部分,mule-descriptor节点是用来描述一个UMO组件的,在这个配置文件里提供了两个UMO组件,在每一个UMO组件里有一个或多个端点(endpint)来接收或发送事件。也许你会觉得这个配置文件过于复杂,以至于无法理解。没关系,在以后的文章里将会进一步解释。在Mule容器里面为UMO组件提供了一系列的服务,例如事务管理,事件转化,路由,事件审核和管理等,Mule将对象分开管理意味着可以将UMO组件交给当前流行的IOC容器(比如spring)去构造。虽然Mule声称与spring可以完美结合,然而在我通过一系列实验中发现,Mule与spring结合还是有许多bug的,希望Mule能在下一个版本的更新中解决。
有人可能会说,Mule只是一个Jms实现,然而Mule不仅仅是一个Jms服务器,而且可以通过配置来使用几乎所有的Jms服务,比如说ActiveMq、JBoss MQ、Joram OpenJms、Oracle AQ、SeeBeyond、Spirit Wave、 UberMQ、Weblogic Jms 和 IBM WebSphere MQ。与Spring一样,Mule不会重复造轮子,而是会使用在当今开源社区里成熟的产品。比如在webservice上,Mule支持glue、axis和xfire。对于不同类型的连接(比如说jms和webservice),Mule提供了一致的服务来管理事件的流向、联系、事务、安全和审核。在使用Mule之前,很有必要理解一些核心的概念和专业术语。以下图表简单的描述了一个Mule服务器的组成 500)this.width=500'> 下面将对图表上的每一个概念进行解释。 The Mule ManagerMule管理器是Mule实例的中心,它的主要作用是管理Mule实例中各种各样的对象,例如:连接器、端点、转换器。这些对象被用来控制在组件中消息的流转以及向组件管理的模型提供服务。The Model 模型是在你组件中被管理和执行的容器,它控制着消息在你组件里的收和发。默认的Mule模型是基于SEDA的,这意味着它使用了一种高效的基于消息队列的模型来达到最佳的性能。UMO ComponentsUMO也就是Universal Message Object(通用消息对象),这是一种能从任何地方收发时间的对象。UMO对象可以是你的业务对象,在消息进来的时候执行你的业务逻辑,这是一种标准的JavaBean,没有任何特殊的Mule代码在你的组件(UMO对象)里面,Mule是如何在你的对象里进行消息收发的路由和转换取决于你在组件里的配置。Endpoints端点是Mule通信能力的基本原理。一个端点定义在两个或者更多组件之间的通信渠道。可以通过配置消息过滤器、安全拦截器和事务处理来控制一个端点是如何将消息收与发的。External Applications外部应用可以是任何的遗留系统。基本上,任何应用只要有一种数据传输方式能通过Mule的端点进行通信,UMO组件是不关心是哪个应用提供的数据、应用部署的地点以及是用何种传输协议的。 |
|
|