将消息从 HTTP 端点发送到 JMS [英] Sending message from HTTP endpoint to JMS

查看:33
本文介绍了将消息从 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.

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.

Heres the route:

<route >
    <from uri="jetty:http://0.0.0.0:8050/add/Customer"/>
    <inOnly uri="jms:queue:Q.Customer" />
</route>

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>

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>

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

This lead to following output:

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆