mule-发送json数据到jms queue

 

这个示例中,一段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





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值