从HTTP端点向JMS发送消息

4
我将尝试创建一个骆驼路由,该路由将在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队列的输入? 谢谢...

在“from”步骤之后添加<convertBodyTo type="java.lang.String"/>,这样行得通吗? - Ralf
不行...即使添加了'convertBodyTo'也不起作用 - user1717230
那我不知道。我设置了一个像你的路由,记录交换体而不是传递消息,并且我POST了你的XML,它对我起作用了。 - Ralf
消息日志对我来说是正确的。但当我尝试将其进一步发送到JMS时,消息体被清空了。 - user1717230
这仍然听起来像“流只能被消费一次”的问题。您确实是在 from 之后立即放置了 convertBodyTo,对吗? - Ralf
1个回答

0

你的路由按预期工作。我使用以下设置进行了测试:

<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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接