【问题标题】:Two different camel routes using same connection with netty4使用与 netty4 相同连接的两条不同的骆驼路线
【发布时间】:2017-07-05 17:57:41
【问题描述】:

我有两条使用 netty4 组件的路由,它们应该读取和写入同一个套接字连接,但由于某种原因无法正常工作。

第一个

from("netty4:tcp://SERVER:PORT?decoder=#packet-decoder&encoder=#packet-encoder&clientMode=true")
.to("seda:inbound") 

第二个:

from("seda:dispatch")
.to("netty4:tcp://SERVER:PORT?decoder=#packet-decoder&encoder=#packet-encoder&sync=true&reuseChannel=true")
.process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                          logger.info("Packet received: " + exchange.getIn().getBody());
                    }
                });

请注意,第一个(“from”)配置为客户端,第二个(“to”)本质上是客户端。

即使我在第二个中使用了reuseChannel,并且正在调用“PacketEncoder”编码方法,也没有抛出异常,也没有发送数据。

public class PacketEncoder extends MessageToByteEncoder<Packet> { 

    public PacketEncoder() { 
    } 

    @Override 
    protected void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf out) throws Exception { 
        out.writeBytes(PacketUtil.convertPacketToBytes(packet, true)); 
    } 

} 

最后,在第二条路由中,“to”端点之后的处理器永远不会被调用。以下内容卡在 NettyProducer 中的某个地方。

我做错了什么?

【问题讨论】:

    标签: sockets synchronization apache-camel netty


    【解决方案1】:

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    
        <route>
            <description>test</description>
            <from uri="activemq:Test" />
            <to   uri="netty4:tcp://localhost:22822?clientMode=true&amp;sync=true&amp;allowDefaultCodec=false&amp;reuseChannel=true"/>
        </route>
    <route>
            <description>Connessione dal ControlCenter alla coda</description>
            <from uri="netty4:tcp://localhost:22822?clientMode=true&amp;sync=true&amp;decoders=#string-decoder&amp;reuseChannel=true" />
            <to   uri="activemq:Test2"/>
        </route>
    </camelContext>
    

    我使用它,但每次打开新的 tcp 客户端时都不工作

    【讨论】:

      【解决方案2】:

      也许您应该将reuseChannel 选项也添加到第一个端点,即“来自”。通道保存在exchange中,所以必须在创建exchange的endpoint中设置option。

      【讨论】:

        猜你喜欢
        • 2018-09-05
        • 1970-01-01
        • 1970-01-01
        • 2016-01-15
        • 2014-02-12
        • 2023-03-04
        • 1970-01-01
        • 1970-01-01
        • 2015-04-06
        相关资源
        最近更新 更多