学习创建一个“Hello World”Mule项目,然后通过Anypoint Studio的嵌入式Mule服务器将其部署为Mule应用程序。最后,使用网络浏览器与您进行交互测试。
现在,您已经在Studio中创建了一个基本应用程序,您可以配置flow元素。 您需要为HTTP连接器提供连接器配置,其中包括:
namehostportHTTP连接器允许您的Mule应用程序通过HTTP或HTTPS协议连接到Web资源。 1. 在画布中,单击HTTP连接器以打开其属性编辑器。 2. 单击加号以添加具有主机和端口号的连接器配置。 3. 在“全局元素属性”对话框中,将Host设置为localhost,接受默认端口8081,单击“确定”。 打开的属性窗口中,path填充为“/”,“连接器配置”填充有对刚刚创建的全局元素的引用。 4. 在画布中,单击HTTP连接器。 红色警告标志从属性编辑器和画布上的连接器消失。 5. 单击画布上的set payload组件以在控制台中打开其属性编辑器。 6. 将Value字段设置为 Hello World!例如。 7. 单击配置XML以查看XML中的更改:
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/> <flow name="basic_tutorialFlow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/> <set-payload value="Hello World!" doc:name="Set Payload"/> </flow> </mule>8 . 单击保存图标保存更改。
你现在已经建立了一个简单的Mule应用程序。
Anypoint Studio具有嵌入式Mule Runtime,用于测试部署。您可以在嵌入式服务器上部署应用程序,以便在部署到生产环境(如首选服务器或Runtime管理器)之前查看它的工作并执行调试功能。
1、在包资源管理器中,右键单击项目名称,然后选择运行方式> Mule应用程序。
Studio在嵌入式服务器上启动应用程序,在控制台中显示其操作。完成后,控制台消息显示为:
“开始应用’basic_tutorial’”
2、打开你最喜爱的Web浏览器。
3、导航到应用程序的URL。
该地址是HTTP连接器默认设置的结果: http://localhost:8081 应用程序通过其HTTP端点接受请求,然后Set Payload组件将有效负载设置为“Hello World!”,然后HTTP连接器返回有效负载作为您在浏览器中看到的响应。 4、在Studio中,通过单击stop.icon控制台上的Terminate停止运行应用程序。