简体   繁体   English

Camel将String发送到JMS队列,但检索字节数组

[英]Camel send String to JMS queue but byte array is retrieved

I have a question related to Camel and JMS message. 我有一个与Camel和JMS消息相关的问题。

My system contains a JMS topic and a JMS queue, say, TopicInput and QueueInput. 我的系统包含一个JMS主题和一个JMS队列,比如TopicInput和QueueInput。 A process of mine listens to QueueInput and process the message send into this queue. 我的进程侦听QueueInput并处理发送到此队列的消息。 The result is then passed to another Topic, say, TopicOutput. 然后将结果传递给另一个Topic,比如TopicOutput。

The process that processes the message uses Java and Apache Camel. 处理消息的过程使用Java和Apache Camel。 The response my Camel route send out is a String. 我的Camel路由发出的响应是一个字符串。 Therefore the String is sent to TopicOutput. 因此,String被发送到TopicOutput。

My problem is that when I send my message to the QueueInput directly, everything is fine, I get a String response from TopicOutput. 我的问题是当我直接将消息发送到QueueInput时,一切都很好,我从TopicOutput得到一个String响应。 However, if I send the request message to the TopicInput, which internally bridges to QueueInput anyway, the result I get from TopicOutput will be a byte array representation of the String. 但是,如果我将请求消息发送到内部桥接到QueueInput的TopicInput,我从TopicOutput获得的结果将是String的字节数组表示。

Does anyone know how this could happen? 有谁知道这会怎么样? I am not even sure whether this is the Camel's problem or JMS problem. 我甚至不确定这是Camel的问题还是JMS问题。

Any suggestions or hints will be helpful. 任何建议或提示都会有所帮助。

Many thanks. 非常感谢。

Not quite sure what's going on exactly in your logic. 不太确定你的逻辑究竟发生了什么。

JMS has BytesMessage and TextMessage. JMS有BytesMessage和TextMessage。 To get a string directly, the message has to be TextMessage, otherwise a String must be constructed from a byte array, which you can retrieve from the message. 要直接获取字符串,消息必须是TextMessage,否则必须从字节数组构造String,您可以从消息中检索该字节数组。

When sending messages using Camel, Camel tries to map the payload to the best JMS message type. 使用Camel发送消息时,Camel会尝试将有效负载映射到最佳JMS消息类型。 Check this table out . 检查这个表

To be sure to always produce a TextMessage (that parses to String), convert the payload to String before sending it with a JMS producer. 为了确保始终生成TextMessage(解析为String),请在将有效负载与JMS生成器一起发送之前将其转换为String。 Make sure you are aware of what the message type and payload is in every step of your flow, then you should easily solve your issue. 确保您了解流程的每个步骤中的消息类型和有效负载,然后您应该轻松解决您的问题。

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

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