繁体   English   中英

apache骆驼多播将文本消息转换为字节消息

[英]apache camel multicast converting text message to byte message

我正在尝试使用带有activemq的apache骆驼向主题发布文本消息。 以下代码工作正常,并且我的客户端程序能够将消息转换为文本消息。

    <route id="setText">
                <from uri="restlet:///test/{testId}?restletMethod=POST" />
                <setExchangePattern pattern="InOnly" />
                <setBody>
                    <simple>${header.testId}:${body}</simple>
                </setBody>
                <to uri="activemq:topic:TestTopic" />
            </route>

现在,我添加了多播以执行多项操作。 多播能够很好地执行并将消息成功发送到主题。

    <route id="setText">
                        <from uri="restlet:///test/{testId}?restletMethod=POST" />
                        <setExchangePattern pattern="InOnly" />
                    <multicast>
                        <pipeline>
                        <!-- some operation -->
                        </pipeline>
                        <setBody>
                            <simple>${header.testId}:${body}</simple>
                        </setBody>
                        <to uri="activemq:topic:TestTopic" />
                    </multicast>
</route>

但是,在将文本消息发送到主题时,多播会将消息转换为字节流。 我的客户端程序无法将已使用的消息转换为TextMessage,因为消息为再见格式,并且以下是针对system.out.println显示的信息(在我的客户端程序中)

ActiveMQBytesMessage {commandId = 5, responseRequired = true, messageId = ID:R-014-49827-1433324560754-3:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:R-014-49827-1433324560754-3:1:1:1, destination = topic://TestTopic, transactionId = null, expiration = 0, timestamp = 1433324582980, arrival = 0, brokerInTime = 1433324582981, brokerOutTime = 1433324583731, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@10d42d49, marshalledProperties = org.apache.activemq.util.ByteSequence@59e91c40, dataStructure = null, redeliveryCounter = 0, size = 0, properties = {breadcrumbId=ID-R-014-49826-1433324557692-2-1, org_DOT_restlet_DOT_http_DOT_version=1.1, testId=3100026, org_DOT_restlet_DOT_startTime=1433324582521, CamelHttpMethod=PUT, CamelHttpUri=http://localhost:8080/service-bus/test/3100026}, readOnlyProperties = true, readOnlyBody = true, droppable = false} ActiveMQBytesMessage{ bytesOut = null, dataOut = null, dataIn = null }

您能建议为什么组播将文本消息转换为字节格式吗? 以及如何以文本格式发送消息? 提前致谢。

我不确定您使用的是哪个版本的骆驼,但是jaxb dataformat将消息转换为字节时遇到了类似的问题。 我建议打开一张吉拉票。 同时,我之前使用的解决方法是在jms端点上强制使用文本类型。

activemq:topic:TestTopic?jmsMessageType=Text

参考: http : //camel.apache.org/jms.html

我在多播和jaxb解组中遇到相同的问题。 如果没有多播,unmarshal()可以正常工作,并且我收到预期的对象类型作为方法“ Handler.received(Object)”的参数。 在多播后面添加unmarshal(),而“ Handler.received(Object)”将获得Byte []。

// works - Handler.received(Object) receives correct object type:
from("test-jms:queue:test.queue").unmarshal(jaxb).to("class:com.test.Handler?method=received");

// doesn't work - Handler.received(Object) receives a byte array:
from("test-jms:queue:test.queue").multicast().unmarshal(jaxb).to("class:com.test.Handler?method=received");

我是骆驼的新手,这使我整日变得疯狂。 上面建议的将jmsMessageType设置为“ Text”的解决方案对我也不起作用。 在那种情况下,Handler类接收到一个包含XML的String,就好像unmarshal()根本没有做任何事情一样。

编辑:我看着下面的StackOverflow问题: Apache骆驼多播FreeMarker

并更改了我的代码以使用“管道”,例如用户“ Claus Ibsen”的示例:

from("test-jms:queue:test.queue").multicast()
.pipeline().to("file://targetdir/received").end()
.pipeline().unmarshal(jaxb).to("class:com.test.Handler?method=received").end()
.end();

现在它像我期望的那样工作。 接收到的XML文件被复制到“ targetdir / received”中,并且方法“ Handler.received(Object)”将获取正确的对象类型作为参数。 谢谢克劳斯! :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM