MULE ESB环境搭建和例子 通过装插件的方式

               

环境搭建和例子:

Download mule standaloe from web site:

1.    http://www.mulesoft.org/download-mule-esb-community-edition

2.    Unzip to a path(such as:D:\mulesl312)

 

Installing Mule IDE in Eclipse

3.    Start Eclipse, and set up a workspace foryour installation of Mule if you haven't already. (Make sure your workspacedoes not have a space in the directory path)

4.    In the workbench view, choose Help >Install New Software.

5.    Press the Add button next to the Work withtext box, enterhttp://dist.muleforge.org/mule-ide/updates/3.4/ and pressEnter. The Mule IDE now appears in your list ofavailable software.

6.    Select the Mule IDE check box and clickNext,and after Eclipse processes for a moment, click Next again.

7.    Review the Mule IDE license, select theoption to accept the license, and then clickFinish.

8.    ClickYes to restart Eclipse.

9.    Set Mule Distributions in eclipse:

 

 

 

 

You are now ready to configure the Muledistribution as described in the next section.

Config MULE_HOME and add bin to path:

10.  MULE_HOME: D:\mulesl312

11.  Path:%Path%; %MULE_HOME%\bin

 

Create a new Mule project:

 

 

How to Import  a  existing project to Mule project and run it:

there is some ecamples in example folder of MULE,wecanimport them

We neeed to add Mule classpath lib to the project

 

Then we can run the project on Muleruntime like as:

 

So server starts:

NFO  2011-06-22 11:38:01,125 [main]org.mule.module.management.agent.JmxAgent: Registered Endpoint Service withname:Mule.04cd6ac8-9c81-11e0-95b7-8bd1ea0dc252:type=Endpoint,service="HelloWorld",connector=connector.http.mule.default,name="endpoint.http.localhost.8888"

INFO  2011-06-22 11:38:01,125 [main]org.mule.module.management.agent.JmxAgent: Registered Connector Service withnameMule.04cd6ac8-9c81-11e0-95b7-8bd1ea0dc252:type=Connector,name="connector.servlet.mule.default.1"

INFO  2011-06-22 11:38:01,125 [main]org.mule.module.management.agent.JmxAgent: Registered Connector Service withnameMule.04cd6ac8-9c81-11e0-95b7-8bd1ea0dc252:type=Connector,name="connector.stdio.mule.default.1"

INFO  2011-06-22 11:38:01,125 [main] org.mule.module.management.agent.JmxAgent:Registered Connector Service with nameMule.04cd6ac8-9c81-11e0-95b7-8bd1ea0dc252:type=Connector,name="connector.VM.mule.default.1"

INFO  2011-06-22 11:38:01,125 [main]org.mule.module.management.agent.JmxAgent: Registered Connector Service withnameMule.04cd6ac8-9c81-11e0-95b7-8bd1ea0dc252:type=Connector,name="connector.http.mule.default.1"

INFO  2011-06-22 11:38:01,140 [main]org.mule.DefaultMuleContext:

**********************************************************************

* Mule ESB and IntegrationPlatform                                 *

* Version: 3.1.2 Build:21975                                       *

* MuleSoft, Inc.                                                    *

* For more information go tohttp://www.mulesoft.org                *

*                                                                   *

* Server started: 11-6-22 上午11:38                               *

* Server ID:04cd6ac8-9c81-11e0-95b7-8bd1ea0dc252                   *

* JDK: 1.6.0_10-rc2 (mixedmode, sharing)                           *

* OS encoding: UTF-8, Muleencoding: UTF-8                          *

* OS: Windows XP - Service Pack3 (5.1, x86)                        *

* Host: PC-201103071221(192.168.40.61)                             *

* Mode: Development                                                 *

*                                                                   *

* Agents Running:                                                   *

*   JMX Agent                                                        *

**********************************************************************

访问URL

 

mule-config.xml:

 <inbound-endpointaddress="http://localhost:8888"transformer-refs="HttpRequestToNameString"exchange-pattern="request-response">

  <not-filter>

  <wildcard-filterpattern="/favicon.ico"/>

        </not-filter>

   </inbound-endpoint>

 

//所有的转换器都在此,就我理解所有的转换过程其实都要自己写,可以自己定义通用的转换器重用并扩展。

//public class ChatStringToString extendsAbstractTransformer 父类

    <custom-transformername="StringToNameString"class="org.mule.example.hello.StringToNameString"/>

    <custom-transformername="NameStringToChatString"class="org.mule.example.hello.NameStringToChatString"/>

    <custom-transformername="ChatStringToString"class="org.mule.example.hello.ChatStringToString"/>

    <custom-transformername="HttpRequestToNameString"class="org.mule.example.hello.HttpRequestToNameString"/>

    <custom-transformername="ExceptionToString"class="org.mule.example.hello.ExceptionToString"/>

    <custom-transformername="HttpRequestToParameter"class="org.mule.transport.servlet.transformers.HttpRequestToParameter"/>

    <custom-transformername="ObjectToString"class="org.mule.transformer.simple.ObjectToString"/>

 

 

 

 

 

 

 

 

理论和模型:

 

1. 简介

Mule ESB是一个基于Java的轻量级企业服务总线和集成平台,允许开发人员快速便利地连接多个应用,并支持应用间的数据交换。Mule ESB支持集成现有系统而无论其底层采用何种技术,如JMS、Web Services、JDBC、HTTP以及其他技术。

2. 整体结构

图整体结构

从上图可见,Mule通过Transports/Connectors与外围的异构系统连接,提供Routing(路由)、Transaction Management(事务管理)、Transformation(转换)、Message Broker(消息代理)、Transportation Management(传输管理)、Security(安全)等核心模块。Mule可以单独使用,也可以架设在常用的应用服务器上。

图架构简图

外围系统的服务请求通过Mule ESB的Transport接入,Mule通过Transformer进行数据的格式转换,然后经过Inbound Router进行消息过滤(内部通过配置filter实现)后交给Mule的Component进行业务逻辑处理,处理后的结果通过Outbound Router确定传递给哪个接收方,然后通过Transformer进行数据格式转换,通过Transport连接至接收方,传递信息。

此图描述的是Mule中的一个典型场景的处理过程,涵盖了Mule中的各个关键组件。其中某些处理步骤不是必须的,如Inbound Router、Transformer。后续可以看到一些其他场景的处理。

3. 功能

a. 服务中介

·        将业务逻辑和消息发送分离

·        屏蔽服务的消息格式和协议

·        提供任意位置的服务调用

·        提供协议桥接

b. 数据转换

·        在应用间交换不同格式的信息 

·        操作消息的负载内容,包括加密、压缩和编码转换

·        在异构的传输协议的数据类型间格式化消息

c. 消息路由

·        基于消息内容和复杂规则路由消息

·        消息的过滤、聚合以及重新排列序号

d. 服务创建和托管

·        暴露端点、EJB、Spring Bean以及POJO作为服务

·        作为轻量级的服务容器进行服务托管

Mule ESB中有一些基本的概念,理解这些基本概念后才能理解Mule的内部机制。从中也可以看到Mule解决问题的基本思路。

 

4. 基本概念

4.1 Model

Model表示托管各个服务的运行时环境。

图 Model

4.2 Service

Service是用来处理服务请求的基本单位,它调用各个组件进行服务请求的处理。

图 Service

4.3 Transport

Transport管理消息的接收和发送,数据转换的过程也是在Transport中通过调用Transformer完成的。

图 Transport

4.3.1 Connector

Connector用于管控特定协议的使用,如HTTP Connector、JMS Connector等。

4.3.2 End-Point

Endpoint用于表示一种协议的特定使用方式,如listening/polling、从中读取、向指定地址写入等,定义了发送和接收消息的通道。Endpoint控制的是底层的实体在Connector中如何被使用。

Endpoint定义于Inbound和Outbound Router中。

4.4 Transformer

Transformer用于转换消息的内容。

图 Transformer

4.5 Router

Router使用Filter基于消息中的属性信息进行消息的分发。

图 Router

Router在Service中的位置决定了Router的性质(inbound、outbound和response)和担任的角色(pass-through、aggregator等)。

4.6 Component

Component是Service的核心部件,是Service的业务逻辑的实现。

图 Component: implicit bridge component

Component可以是Java Class(POJO、Spring Bean)、Web Service、Script等。

Component可定义自己的生命周期:initialise、start、stop、dispose,不过需要实现Mule的LifeCycle接口。Mule 3.0版本开始提供@PostConstruct和@PreDestroy的注解,对应生命周期的initialise和dispose阶段,不需要实现Mule的LifeCycle接口了。

4.7 Flow(@since 3.0)

Flow是Mule 3.0新引入的,包含一个消息源(Message Source)和多个消息处理器组成的处理器链。

图 Flow

 

根据实际需求着重检查了一下Mule ESB的消息传递方式。Mule支持常用的几种消息传递方式,能够满足要求。

 

5. 消息传递方式

5.1 异步方式

异步方式是一种单向调用,调用者不需要获得响应。

图 Asynchronous

异步方式通过inbound和outbound endpoint的exchange-pattern=”one-way”实现。

使用基本的Stdio Transport验证,通过标准输入传输字符串,将其原样传递给标准输出进行显示。相应配置如下:

 

xml 代码

1.  <service name="echo">    

2.      <inbound>    

3.          <stdio:inbound-endpoint system="IN" exchange-pattern="one-way" />    

4.      </inbound>    

5.          

6.      <component>    

7.          <singleton-object class="demo.mule.umo.StdIo" />    

8.      </component>    

9.          

10.     <outbound>    

11.         <pass-through-router>    

12.             <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" />    

13.         </pass-through-router>    

14.     </outbound>    

15. </service>    

运行服务,控制台显示结果如下:

 

1.  Please enter: Hello, world!    

2.  INFO  2010-12-07 19:21:18,877 [ConsoleConnector.dispatcher.1]    

3.      org.mule.lifecycle.AbstractLifecycleManager: Initialising:    

4.      'ConsoleConnector.dispatcher.23255376'. Object is: StdioMessageDispatcher    

5.  INFO  2010-12-07 19:21:18,877 [ConsoleConnector.dispatcher.1]    

6.      org.mule.lifecycle.AbstractLifecycleManager: Starting:    

7.      'ConsoleConnector.dispatcher.23255376'. Object is: StdioMessageDispatcher    

8.  Hello, world!    

其中INFO输出是Mule第一次初始化相应Connector打印出来的,之后调用服务不会再次显示。

异步方式适用于简单的消息传递的场景。

5.2 请求-响应方式

请求-响应方式即请求方调用服务后,服务立即处理并返回响应结果,不需将消息再次传递。

图 Request-Response

请求-响应方式通过input endpoint的exchange-pattern=”request-response”实现,相应配置如下:

 

xml 代码

1.  <strong>  

2.      <strong>  

3.          <model name="services">        

4.              <service name="echoService">        

5.                  <inbound>        

6.                      <inbound-endpoint address="http://localhost:7007/services/Echo"        

7.                          exchange-pattern="request-response">        

8.                          <cxf:jaxws-service />        

9.                      </inbound-endpoint>        

10.                 </inbound>        

11.                 <component>        

12.                     <singleton-object class="demo.mule.umo.Echo" />        

13.                 </component>        

14.             </service>        

15.         </model>  

16.     </strong>  

17. </strong>   

上边是通过service配置的,通过flow配置如下:

 

xml 代码

1.  <flow name="EchoFlow">        

2.      <inbound-endpoint address="http://localhost:7007/services/Echo"        

3.          exchange-pattern="request-response" />        

4.      <cxf:jaxws-service serviceClass="demo.mule.umo.Echo" />        

5.      <component>        

6.          <singleton-object class="demo.mule.umo.Echo" />        

7.      </component>        

8.  </flow>    

在浏览器中输入“http://localhost:7007/services/Echo/echo/text/hello,world”,浏览器中会显示“hello,world”的输出信息。

请求-响应方式适用于单次服务调用的场景。

5.3 同步方式

同步方式即请求方调用服务后,component将处理结果发送给另一个外部服务处理,并将处理结果反方向返回。

图 Synchronous

同步方式通过inbound和outbound endpoint的exchange-pattern=”request-response”实现,相应配置如下:

 

xml 代码

1.  <flow name="echo">      

2.      <inbound-endpoint address="http://localhost:7007/services/Echo"      

3.          exchange-pattern="request-response" />      

4.      <cxf:jaxws-service serviceClass="demo.mule.umo.Echo" />      

5.      <component>      

6.          <singleton-object class="demo.mule.umo.StdIo" />      

7.      </component>      

8.      <vm:outbound-endpoint path="vm" exchange-pattern="request-response" />      

9.  </flow>      

10. <flow name="vm">      

11.     <vm:inbound-endpoint path="vm" exchange-pattern="request-response" />      

12.     <component>      

13.         <singleton-object class="demo.mule.umo.Vm" />      

14.     </component>      

15.     <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" />      

16. </flow>    

同步方式适用于通过Mule调用远程服务的场景。

5.4 异步请求-响应方式

异步请求-响应方式即请求方调用服务后不需要立即获得返回结果,component将请求发送给其他外围系统处理(可能有多个),全部处理完毕后通过指定的异步应答Router返回给请求方。

图 Asynchronous Request-Response

异步请求-响应方式通过在OutBound Endpoint中增加reply-to以及增加async-reply节点实现,响应配置如下:

 

xml 代码

1.  <flow name="echo">      

2.      <inbound-endpoint address="http://localhost:7007/services/Echo"      

3.          exchange-pattern="request-response" />      

4.      <cxf:jaxws-service serviceClass="demo.mule.umo.Echo" />      

5.      <component>      

6.          <singleton-object class="demo.mule.umo.StdIo" />      

7.      </component>      

8.      <vm:outbound-endpoint path="vm" exchange-pattern="request-response" />      

9.  </flow>      

10. <flow name="vm">      

11.     <vm:inbound-endpoint path="vm" exchange-pattern="request-response" />      

12.     <component>      

13.         <singleton-object class="demo.mule.umo.Vm" />      

14.     </component>      

15.     <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" />      

16. </flow>    

异步请求-响应方式适用于请求需要被多个远程服务并行处理,结果需要汇总处理后返回的场景。

注:上述代码未运行通过,queue1和queue2获得了请求消息并正常处理,但返回至async-reply时抛出异常,暂未定位到问题。

后将collection-async-reply-router改为single-async-reply-router未报异常,代码示例如下:

 

xml 代码

1.  <em><service name="async req-rep">      

2.      <inbound>      

3.          <stdio:inbound-endpoint ref="stdioInEndpoint" />      

4.      </inbound>      

5.      <component class="demo.mule.umo.Echo" />      

6.      <outbound>      

7.          <multicasting-router>      

8.              <vm:outbound-endpoint path="async.queue1" exchange-pattern="one-way" />      

9.              <vm:outbound-endpoint path="async.queue2" exchange-pattern="one-way" />      

10.             <reply-to address="vm://reply" />      

11.         </multicasting-router>      

12.     </outbound>      

13.     <async-reply timeout="5000" failOnTimeout="true">      

14.         <vm:inbound-endpoint path="reply" exchange-pattern="one-way" />      

15.         <single-async-reply-router />      

16.     </async-reply>      

17. </service></em>  

 

 

附加参考图:

 

&n

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值