您的位置:首页 > 产品设计 > UI/UE

mule-发送json数据到jms queue

2016-07-10 07:55 357 查看
 

这个示例中,一段json的销售数据以字节流的格式向HTTP接口发送请求,转换器将之转换成字符。发送成功的报文会被打印并且增加到JMS queue中等待被消费。

最后到达JMS queue的报文可以在activeMQ的后台管理界面中被查看到。



<?xml version="1.0" encoding="UTF-8"?>
<mule  xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
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/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"> <jms:activemq-connector doc:name="Active MQ"
name="Active_MQ" validateConnections="true" brokerURL="tcp://localhost:61616"/>
<http:listener-config doc:name="HTTP Listener Configuration"
host="localhost" name="HTTP_Listener_Configuration" port="8081" />
<flow name="json-to-jmsFlow">
<http:listener allowedMethods="POST"
config-ref="HTTP_Listener_Configuration" doc:name="HTTP" path="sales1" />

<byte-array-to-string-transformer
doc:name="Convert Byte Array to String" />
<jms:outbound-endpoint connector-ref="Active_MQ"
doc:name="Send to JMS queue" name="jms" queue="sales" />
<logger doc:name="Logger" level="INFO" />
</flow>
</mule>


操作步骤

1.启动mule应用

2.启动activMQ

2.用postman 向HTTP 服务地址http://localhost:8081/sales1 发送POST请求 json数据 

{"ITEM_ID"= 001, "ITEM_NAME" = "Shirt", "QTY" = 1, "PRICE" = 20} 

3.执行成功后访问 http://localhost:8161/admin/queues.jsp
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: