我正在尝试使用 Camel 路由,它将接受 http 端点上的有效负载,然后将该有效负载写入 JMS 队列。
我到目前为止的路线如下。但是一条空消息被传递到 jms 队列。消息到达那里,但没有正文。
路线如下:
<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
”端点的有效负载:
<Customer xmlns="http://www.openapplications.org/9" xmlns:lw="http://www.org/9">
<Name>John</Name>
<Gender>Female</Gender>
</Customer>
有任何关于为什么消息正文没有被写入 jms 队列的输入吗? 谢谢...
最佳答案
您的路线按预期运行。我使用以下设置对其进行了测试:
<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
帮助器类测试了路线:
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>
关于java - 从 HTTP 端点发送消息到 JMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23294816/