Mule构建一个Hello World应用程序

本文介绍如何使用Mule Studio创建一个简单的HelloWorld应用程序。包括项目的创建、配置及部署过程。

构建一个Hello World应用程序

假设

本教程假设您拥有的 下载,安装并启动了Mule工作室  你阅读 Mule工作室的必需品 

创建一个新项目

  1. 在工作室中,单击 File 然后选择 New > Mule Project 
  2. 工作室打开 New Mule Project 向导。 在 Name 字段中,输入的值 My First Project 然后单击 Finish。 



  3. 打开一个空白的画布。 开始设计您的项目通过拖拽  HTTP Endpoint 从 palette 到 canvas 。 请注意,Studio自动包装的端点 flow,从而节省您的步骤手动创建一个。 



  4. 添加到流的  Echo Component ,拖着它旁边的HTTP端点在画布上。 单击 Configuration XML 选项卡(底部的画布上)看到您的应用程序用XML表示。 工作室的双向编辑功能可以确保你在图形界面中添加或更改反映在XML配置。 (使用下面的选项卡来查看应用程序的图形和XML表示)。

  5. 单击 Message Flow 选项卡回到图形化编辑器,然后单击 save 图标来保存您的项目。

 

配置项目

既然已经建模工作室基本的应用程序,你可以采取的步骤配置每个单独的元素。

  1. 在画布上单击HTTP端点开放 Properties Editor 在控制台(见下图)。
  2. HTTP端点 允许Mule应用程序连接到Web资源通过HTTP或HTTPS协议。 在一个更复杂的应用程序中,您将使用这个编辑器来配置端点的值的属性,定义应用程序的连接细节。 对于这个项目,k 所有字段保留默认值。 



  3. 单击 Echo Component 在画布上开放  Properties Editor 在控制台(见下图)。
  4. 回声组件仅返回响应HTTP请求消息有效负载。 对于这个项目,k 所有字段保留默认值。 



  5. 再次,您可以单击 Configuration XML 查看您的更改在XML配置(请参见下面的代码)。 单击 save 图标以保存您的更改。

    <? xml version = "1.0" encoding = "UTF-8" ?>
     
    < mule xmlns:http = "<a href="http://www.mulesoft.org/schema/mule/http" "="" style="color: rgb(0, 136, 204); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background: none !important;">http://www.mulesoft.org/schema/mule/http" xmlns = "<a href="http://www.mulesoft.org/schema/mule/core" "="" style="color: rgb(0, 136, 204); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background: none !important;">http://www.mulesoft.org/schema/mule/core" xmlns:doc = "<a href="http://www.mulesoft.org/schema/mule/documentation" "="" style="color: rgb(0, 136, 204); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background: none !important;">http://www.mulesoft.org/schema/mule/documentation" xmlns:spring = "<a href="http://www.springframework.org/schema/beans" "="" style="color: rgb(0, 136, 204); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background: none !important;">http://www.springframework.org/schema/beans" version = "EE-3.4.0" xmlns:xsi = "<a href="http://www.w3.org/2001/XMLSchema-instance" "="" style="color: rgb(0, 136, 204); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background: none !important;">http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/http <a href="http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd" "="" style="color: rgb(0, 136, 204); border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background: none !important;">http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
         < flow name = "My_First_MuleFlow1" doc:name = "My_First_MuleFlow1" >
             < http:inbound-endpoint  exchange-pattern = "request-response" host = "localhost" port = "8081" doc:name = "HTTP" />
             < echo-component  doc:name = "Echo" />
         </ flow >
    </ mule >

部署项目

Mule工作室有自己的嵌入式服务器捆绑在一起,适合测试时部署代码。 嵌入式服务器上部署您的应用程序可以看到它工作和执行任何调试活动部署到生产环境之前如一个服务器或前提 CloudHub 

  1. 在 Package Explorer右键单击项目名称,然后选择 Run As > Mule Application 
  2. 工作室嵌入式服务器上启动应用程序,显示在控制台的行为。 完成后,控制台消息读取 Started app 'my_first_project'




与项目交流

  1. 打开一个Web浏览器。
  2. 导航到您的应用程序的URL,附加一个字符串,成为消息有效负载。 例如: 

    http://localhost:8081 / Hello_world 

  3. 接受请求的应用程序通过HTTP端点,然后“回声”相同的载荷响应在您的浏览器中。 



  4. 在工作室,停止应用程序使用  terminate 图标在控制台(见下文)。 

 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值