【问题标题】:Sending message from HTTP endpoint to JMS将消息从 HTTP 端点发送到 JMS
【发布时间】:2014-06-11 06:26:09
【问题描述】:

我正在尝试使用骆驼路由,它将接受 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 步骤后添加&lt;convertBodyTo type="java.lang.String"/&gt; 是否有效?
  • 不...即使在添加 'convertBodyTo' 后也不起作用
  • 那我不知道。我像您一样设置了一条路由,记录了交换主体而不是传递消息,并发布了您的 XML,它对我有用。
  • 对我来说也正确记录了消息。当我尝试将其进一步发送到 jms 时,正文被清空了。
  • 这听起来仍然像是“流只能消费一次”的问题。您确实将 convertBodyTo 放在 from 之后,不是吗?

标签: java jms apache-camel activemq


【解决方案1】:

您的路线按预期运行。我使用以下设置对其进行了测试:

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

【讨论】:

    猜你喜欢
    • 2016-03-02
    • 2018-07-30
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    • 2013-09-02
    相关资源
    最近更新 更多