java - 从 HTTP 端点发送消息到 JMS

标签 java jms apache-camel activemq

我正在尝试使用 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/

相关文章:

java - org.springframework.beans.factory.UnsatisfiedDependencyException : Unsatisfied dependency expressed through method 'anyMethodName' parameter 0:

java - 如何解密从服务器收到的字符串?

java - JMS MessageDriven bean - 如何同步线程?

java - NoClassDefFoundError javax/jms/Message 即使在指定类路径时也是如此

java - 反序列化 JMS 消息中的对象

java - Apache Camel 消费者

java - 改进解析文本文件的代码

java - 使用 apache Camel 向远程 Web 服务发送 SOAP 请求并获取响应

elasticsearch - 如何迫使Camel Elasticsearch在测试中不启动本地节点?

java - ActiveMQ/JMS - 如果消息发送失败,请勿重试