如果我有以下骆驼路线并发送udp消息,则不会将任何内容打印到标准输出:
<route>
<from uri="netty:udp://0.0.0.0:5000"/>
<to uri="mock:stdout"/>
</route>
但是,如果我添加解码器,我可以看到 udp 消息打印在标准输出上
<bean class="org.jboss.netty.handler.codec.string.StringDecoder" id="stringDecoder">
<constructor-arg value="UTF-8"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="netty:udp://0.0.0.0:5000?decoder=#stringDecoder"/>
<to uri="mock:stdout"/>
</route>
</camelContext>
有人可以解释一下为什么默认解码器不会将消息传递到模拟端点。它正在等待EOF类型的信号吗?
我使用以下方法发送消息:
$ cat json.txt | nc -4u -w1 hostname 5000
Apache Camel netty page 解释说:
allowDefaultCodec == true
Camel 2.4: The netty component installs a default codec if both,
encoder/deocder is null and textline is false.
Setting allowDefaultCodec to false prevents the netty component from installing a
default codec as the first element in the filter chain.
字符串解码器要求您使用新行来终止字符串。因此,请确保在发送时包含它。
例如,在javadoc和代码示例中,您可以看到他们使用n
https://docs.jboss.org/netty/3.2/api/org/jboss/netty/handler/codec/string/StringDecoder.html