mule esb_Mule ESB –入门

Mule ESB是一个轻量级但可扩展的Java ESB,用于构建高性能、安全的多协议交互。它提供数据转换、服务调解等功能,支持30多种协议。Mule ESB的优势在于其可扩展性、松散耦合和可伸缩性,适用于需要集成异构系统的场景。Mule ESB的消息结构包括元数据和业务信息两部分,而Mule运行时环境包括社区版和企业版。

mule esb

什么是Mule ESB? (What is Mule ESB?)

Mule, the runtime platform and a nimble Java-based enterprise service (ESB) which allows developers to easily build high-performance, secure, multi-protocol interactions between heterogeneous systems and services. It enables easy integration of existing systems, regardless of the different technologies that the applications use. The exchange of data between applications is carried by different messaging format.

Mule,运行时平台和灵活的基于Java的企业服务(ESB),使开发人员可以轻松地在异构系统和服务之间建立高性能,安全,多协议的交互。 无论应用程序使用何种技术,它都可以轻松集成现有系统。 应用程序之间的数据交换由不同的消息传递格式进行。

Following are the powerful capabilities of Mule ESB:

以下是Mule ESB的强大功能:

  • Data Transformation

    数据转换
  • Service Mediation

    服务调解
  • Service creation and hosting

    服务创建和托管
  • Message Routing

    邮件路由

Mule ESB的优势 (Advantages of Mule ESB)

  • Lightweight but scalable, permitting you to start small and connect more applications in future.

    轻巧但可扩展,可让您从小处着手,并在将来连接更多应用程序。
  • Well suited to the scenarios where loose coupling, robustness, and scalability required.

    非常适合需要松散耦合,鲁棒性和可伸缩性的方案。
  • It has support for more than 30 protocols and technologies.

    它支持30多种协议和技术。
  • Mule platform encourages component reuse profusely; no need to run or add Mule specific code in any of the component. Also, the business logic is separated from messaging logic.

    Mule平台鼓励大量重复使用组件; 无需在任何组件中运行或添加Mule特定代码。 而且,业务逻辑与消息传递逻辑是分开的。
  • Mule does not force any design constraints while choosing messaging format. It varies from SOAP to Binary image files.

    选择消息格式时,Mule不会强加任何设计约束。 从SOAP到Binary图像文件,它都不同。

Mule ESB架构 (Mule ESB Architecture)

Mule ESB Architecture

Mule ESB Architecture

Mule ESB架构

ule子消息结构 (Mule Message Structure)

It is the data format which is internally used by Mule to communicate between different applications via one or more flows.

它是Mule内部用于通过一个或多个流在不同应用程序之间进行通信的数据格式。

Mule Message Structure

Mule Message Structure

ule子消息结构

Primarily it consists of two main parts:

它主要包括两个主要部分:

  1. Header — which is nothing but the metadata of message.

    标头-只是消息的元数据。
  2. Payload — which is the actual business message.

    有效负载-这是实际的业务信息。

Message Object is used to envelop the Mule Message along with some extra attributes like Attachment, Variable, and Exception Payload — which may not appear in every case.

消息对象用于包裹Mule消息以及一些附加属性,例如附件,变量和异常有效负载-可能不会在每种情况下都出现。

The metadata is represented by properties— which provides useful information in order to facilitate processing and avoid errors when the message enters new flow or being transmitted to another application. Properties and Variables, contained within Mule Object, keep data in key-value format.

元数据由属性表示,这些属性提供有用的信息,以便在消息进入新流或传输到另一个应用程序时促进处理并避免错误。 包含在Mule对象中的属性和变量将数据保留为键值格式。

Properties have two main scopes:

属性有两个主要范围:

  • Inbound Properties:
    1. These are immutable, automatically generated by the message source.
    2. They deter scrambling of data formats and any other manipulation in message lifecycle.
    3. Inbound properties’ scope is limited to only a flow; once message whisks to another flow, its inbound properties are disappeared.
    4. Mule Expression Language (MEL) Example: #[message.outboundProperties]

    入站属性:
    1. 这些是不可变的,由消息源自动生成。
    2. 它们阻止了数据格式的混乱以及消息生命周期中的任何其他操作。
    3. 入站属性的范围仅限于流; 一旦消息跳到另一个流,它的入站属性就会消失。
    4. ule子表达语言(MEL)示例: #[message.outboundProperties]
  • Outbound Properties:
    1. These are mutable and can be set by Mule or a user can alter them by using transformer elements in the flow.
    2. They can become inbound properties when message passed outbound endpoint of one flow to inbound endpoint of another flow.
    3. In one case—if message is passed to any flow-ref, then the outbound properties remain same as outbound properties.
    4. MEL Example: #[message.inboundProperties]

    出站属性:
    1. 这些是可变的,可以由Mule设置,或者用户可以通过在流中使用变形器元素来更改它们。
    2. 当消息将一个流的出站端点传递到另一流的入站端点时,它们可以成为入站属性。
    3. 在一种情况下,如果将消息传递到任何流引用,则出站属性与出站属性保持相同。
    4. MEL示例: #[message.inboundProperties]

Variables have three scopes:

变量具有三个作用域:

  1. Flow Variables— can be accessed within the same flow.

    流变量-可以在同一流中访问。
  2. Session Variables— apply across the flows within the same application.

    会话变量-适用于同一应用程序中的流。
  3. Record Variables— apply to only to records processed under batch

    记录变量—仅适用于按批处理的记录

Message Payload contains the data your Mule application processes. Payload changes during its journey through different flow. It is set, enriched, or transformed into the new format by various of a Message processor in a Mule flow.

消息有效负载包含您的Mule应用程序处理的数据。 有效载荷在通过不同流程的过程中会发生变化。 它由Mule流中的各种Message处理器设置,丰富或转换为新格式。

MEL Example to extract payload information: #[payload]

MEL提取有效载荷信息的示例: #[payload]

ule子运行时设置 (Mule Runtime Setup)

Anypoint Studio Hello World项目 (Anypoint Studio Hello World Project)

Let’s construct an application step by step which returns “Hello Mule” message to the browser when you hit the service.

让我们逐步构建一个应用程序,当您点击该服务时,该应用程序会向浏览器返回“ Hello Mule”消息。

  1. Launch the Anypoint Studio platform by navigating to a directory on your local machine where you installed.

    通过导航到本地计算机上安装的目录来启动Anypoint Studio平台。
  2. Create new Mule project, either by hitting “Create Project” link appeared on the Welcome screen or by navigating to File > New > Mule Project.

    通过单击“欢迎”屏幕上出现的“创建项目”链接或导航至“ 文件”>“新建”>“ Mule项目 ”,创建新的Mule项目
  3. Enter the name of your project in “Project Name” section.

    在“项目名称”部分输入您的项目名称。
  4. Anypoint Studio Create New Project

    Anypoint Studio Create New Project

    Anypoint Studio创建新项目

  5. Click on Finish, and you will see Studio Canvas screen as following:

    单击完成,您将看到Studio Canvas屏幕,如下所示:
  6. Anypoint Studio Hello World Project Structure

    Anypoint Studio Hello World Project Structure

    Anypoint Studio Hello World项目结构

  7. At the bottom of canvas there are three tabs—Message Flow, Configuration XML and Global Elements. Message Flow and Configuration XML are the two tabs to show or edit Mule flow in visual and xml format, respectively. Global Elements tab exudes properties for configuration elements having scope global.

    在画布的底部,有三个选项卡-消息流,配置XML和全局元素。 消息流和配置XML是分别以可视和XML格式显示或编辑Mule流的两个选项卡。 “全局元素”选项卡散布具有全局范围的配置元素的属性。
  8. Select a HTTP connector from Mule Palette and drag it into canvas.

    从Mule Palette中选择一个HTTP连接器并将其拖到画布中。
  9. Anypoint Studio Hello Mule HTTP Connector

    Anypoint Studio Hello Mule HTTP Connector

    Anypoint Studio Hello Mule HTTP连接器

  10. Go to the HTTP Listener configuration panel – clicking on green plus symbol under General settings in HTTP Connector – and enter Host and Port values.

    转到HTTP侦听器配置面板-单击HTTP连接器中“常规设置”下的绿色加号-并输入主机和端口值。
  11. Mule ESB HTTP Connector Settings

    Mule ESB HTTP Connector Settings

    Mule ESB HTTP连接器设置

    Mule ESB HTTP Listener Configurations

    Mule ESB HTTP Listener Configurations

    Mule ESB HTTP侦听器配置

  12. Search for the Set Payload and drag the transformer to the flow.

    搜索“设置有效载荷”,然后将变压器拖动到流中。
  13. Mule Message Set Payload

    Mule Message Set Payload

    ule子消息集有效载荷

  14. Click on Set Payload transformer and set the Value field as “Hello Mule”.

    单击“设置有效负载转换器”,并将“值”字段设置为“ Hello Mule”。
  15. Mule Message Payload Value

    Mule Message Payload Value

    ule子消息有效载荷值

  16. Drag the Logger and set the payload value received from Set Payload transformer into Message.

    拖动记录器,并将从“设置有效载荷”转换器接收到的有效载荷值设置为“消息”。
  17. Anypoint Studio Logger

    Anypoint Studio Logger

    Anypoint Studio记录器

  18. After connecting all the Mule components, you flow, in XML format, looks like this:
    <flow name="hellomuleexampleFlow">  
        <https:listener config-ref="HTTP_Listener_Configuration" path="/message"  doc:name="HTTP"/>  
        <set-payload value="Hello Mule" doc:name="Set Payload"/>  
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>  		
    </flow>

    连接所有Mule组件后,您将以XML格式进行如下所示的流程:
  19. To test your application — run it as Mule Application. You can see console logs as below to verify the application is deployed and started successfully.

    要测试您的应用程序—将其作为Mule Application运行。 您可以看到以下控制台日志,以验证应用程序已部署并成功启动。
  20. Anypoint Studio Run As Mule Application

    Anypoint Studio Run As Mule Application

    Anypoint Studio运行为M子应用程序

  21. Fire up the browser and hit the address https://localhost:8081/message. You can see response as “Hello Mule”.

    启动浏览器,并点击地址https://localhost:8081/message 。 您可以看到响应为“ Hello Mule”。
  22. Mule Hello World Web Application

    Mule Hello World Web Application

    Mule Hello World Web应用程序

GitHub Repository. GitHub Repository上找到完整的代码。

翻译自: https://www.journaldev.com/24433/mule-esb

mule esb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值