从 HTTP 端点向 JMS 发送消息 [英] Sending message from HTTP endpoint to JMS
问题描述
我正在尝试使用骆驼路由,它会在 http 端点上接受负载,然后将该负载写入 JMS 队列.
I am trying to have a camel route, which would accept a payload on a http endpoint and then write that payload to a JMS queue.
我目前的路线如下.但是一个空消息被传递到 jms 队列.一条消息到达那里,但它没有正文.
The route that I have so far is below. But an empty message gets delivered to the jms queue. A message gets there, but it has no body.
路线如下:
<route >
<from uri="jetty:http://0.0.0.0:8050/add/Customer"/>
<inOnly uri="jms:queue:Q.Customer" />
</route>
这是我发送到http://0.0.0.0:8050/add/Customer
"端点的有效负载:
Heres the payload that I'm sending into to 'http://0.0.0.0:8050/add/Customer
' endpoint:
<Customer xmlns="http://www.openapplications.org/9" xmlns:lw="http://www.org/9">
<Name>John</Name>
<Gender>Female</Gender>
</Customer>
关于为什么消息正文没有被写入 jms 队列的任何输入?谢谢...
Any inputs on why the message body is not being written to the jms queue? Thanks...
推荐答案
您的路由按预期工作.我使用以下设置对其进行了测试:
Your routes worked as expected. I tested it with following setup:
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true" persistent="false">
<transportConnectors>
<transportConnector uri="tcp://localhost:61616" />
</transportConnectors>
</broker>
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="failover:tcp://localhost:61616" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route >
<from uri="jetty:http://0.0.0.0:8050/add/Customer"/>
<inOnly uri="jms:queue:Q.Customer" />
</route>
<route>
<from uri="jms:queue:Q.Customer" />
<log message="Body: ${body}" />
</route>
</camelContext>
我使用 org.apache.camel.spring.Main
辅助类测试了路由:
I tested the route using the org.apache.camel.spring.Main
helper class:
Main main = new Main();
main.setApplicationContextUri("META-INF/spring/jms-inout-producer.xml"); // change this
main.start();
final Object body = "<Customer xmlns=\"http://www.openapplications.org/9\" xmlns:lw=\"http://www.org/9\"><Name>John</Name><Gender>Female</Gender></Customer>";
final ProducerTemplate template = main.getCamelTemplate();
template.requestBody("http://localhost:8050/add/Customer", body);
这导致以下输出:
INFO Body: <Customer xmlns="http://www.openapplications.org/9" xmlns:lw="http://www.org/9"><Name>John</Name><Gender>Female</Gender></Customer>
这篇关于从 HTTP 端点向 JMS 发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!