LengthFieldBasedFrameDecoder不起作用

问题描述 投票:0回答:2

我在Spring DSL中有以下代码

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd 
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        "
    >

    <util:list id="decoders" list-class="java.util.LinkedList">
        <bean id="length-decoder" class="org.apache.camel.component.netty.ChannelHandlerFactories" factory-method="newLengthFieldBasedFrameDecoder">
            <constructor-arg value="5000"/>
            <constructor-arg value="0"/>
            <constructor-arg value="4"/>
            <constructor-arg value="0"/>
            <constructor-arg value="4"/>
        </bean>
        <bean id="string-decoder" class="org.jboss.netty.handler.codec.string.StringDecoder"/>
    </util:list>

    <bean id="length-decoder" class="org.apache.camel.component.netty.ChannelHandlerFactories" factory-method="newLengthFieldBasedFrameDecoder">
        <constructor-arg value="5000"/>
        <constructor-arg value="0"/>
        <constructor-arg value="4"/>
        <constructor-arg value="0"/>
        <constructor-arg value="4"/>
    </bean>

    <bean id="string-decoder" class="org.jboss.netty.handler.codec.string.StringDecoder"/>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="netty:tcp://10.1.33.204:9001?keepAlive=true&decoders=#length-decoder,#string-decoder&disconnect=true" />
            <log message="${body}" loggingLevel="INFO"/>
            <to uri="direct:SMSRequests"/>
        </route>

        <route>
           <from uri="direct:SMSRequests"/>
           <log message="${body}" loggingLevel="INFO"/>
           <setBody><simple>0004THIS</simple></setBody> <!--hardcoded response-->
           <log message="response --- ${body}" loggingLevel="INFO"/>
         </route>
    </camelContext>

</beans>

我的输入就像1200<XML>....</XML>,其中1200是从<XML>开始的消息的长度。

我的问题是:

  1. 我看到请​​求正在到达9001端口,并且正在到达Netty,但Netty无法解码它们。
  2. 网络没有解码消息(我是否还需要添加编码器?)
  3. 而且,我是否需要将解码器添加到注册表?我猜豆是在Spring DSL中的注册表中自动查找的。
  4. 也没有响应发送给呼叫者。
spring apache-camel netty fuseesb jbossfuse
2个回答
0
投票
  • 如果您未在uri中引用集合,则无需定义decoders
  • 如果您不发送数据 Netty服务器并且仅接收数据来自 Netty服务器,则不需要任何编码器
  • 您需要将length-decoder和/或string-decoder添加到注册表中,否则您将无法在uri中引用它们
  • 如果没有偏移,也许可以将lengthFieldOffsetlenght-decoder的第一个构造函数参数)设置为0

0
投票

我在代码中使用了上述相同的方法,但是,没有收到消息给netty客户。请对此提供帮助。>

© www.soinside.com 2019 - 2024. All rights reserved.