问题描述
我有一个 Camel Netty 路由,它将 XML 发送到服务器端口并将其放入 JMS 消息中.在第一条消息之后,其他每条消息的顶部都有一个换行符,导致我的 XML 在 GUI 接收到它时无法解组.
I have a Camel Netty route that takes XML sent to a server port and places it in a JMS message. After the first message, every other message has a newline at the top of the message, causing my XML to fail to unmarshall when a GUI receives it.
我的路线是这样的:
<route>
<from uri="netty4:tcp://localhost:5150?decoders=#customFrameDelimeterDecoder,#string-decoder&encoder=#string-encoder"/>
<to uri="jms:topic:my.company.topic"/>
</route>
注意:XML 不是换行符终止的,因此需要自定义帧分隔符解码器.
Note: The XML is not newline terminated, hence the need for a custom frame delimeter decoder.
推荐答案
试试设置:
<from uri="netty4:tcp://localhost:5150?textline=true&delimiter=NULL"/>
问题是 camel-netty4
是 由于编解码器文本向您的消息添加分隔符,所以它似乎放置了一个空字符串在您的消息末尾.
The problem is that camel-netty4
is adding a delimiter to your message because of the codec text, so it seems that it is putting a empty string at the end of your message.
您也可以尝试将 autoAppendDelimiter
添加为 false.根据文档:
You could also try to add autoAppendDelimiter
to false. According to docs:
分隔符 |线 |用于文本行编解码器的分隔符.可能的值为 LINE 和 NULL
autoAppendDelimiter |真实 |使用 textline 编解码器发送时是否自动附加缺少的结束分隔符.
autoAppendDelimiter | true | Whether or not to auto append missing end delimiter when sending using the textline codec.
干杯!
抱歉,我试图回答您标记为重复的其他问题.但也许这个答案也适合.告诉我.
Sorry, I was trying to answer your other question that was marked as duplicated. But maybe this answer also fits. Let me know.
这篇关于为什么我的 Camel Netty 路由在 JMS 消息的开头添加换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!