【问题标题】:Reusing routes for inbound/outbound communication重用路由进行入站/出站通信
【发布时间】:2014-09-05 15:25:34
【问题描述】:

我有以下两条路线:

路线 1

from("netty:tcp://localhost:5050?textline=true&encoder=#customStringEncoder&decoder=#customDecoder")
            .routeId("inboundSocketRoute")
            .doTry()
            .unmarshal(beanIO)
            .bean(inboundInterfaceProcessor, "processInterfaceData")
            .doCatch(ValidationException.class, UnidentifiedRecordException.class, InvalidRecordException.class)
            .bean(inboundInterfaceProcessor, "processInterfaceDataError")
            .end();

路线 2

String server = "123.45.67.89:5050";
from("jms://queue:evOutboundDataInterface")
            .routeId("outboundInterfaceRoute")
            .doTry()
            .bean(outboundInterfaceProcessor, "processOutboundData")
            .to("netty:tcp://" + server + "?textline=true&requestTimeout=10000&encoder=#customStringEncoder&decoder=#customDecoder")
            .bean(outboundInterfaceProcessor, "processSequence")
            .doCatch(ReadTimeoutException.class)
            .bean(outboundInterfaceProcessor, "handleTimeout")
            .doCatch(ConnectException.class)
            .bean(outboundInterfaceProcessor, "handleConnectionError")
            .end();

Route 1 由来自外部服务器的传入数据触发。传入的数据由 BeanIO 解析,最终在我的InterfaceProcessor 中结束,它处理入站数据。 Route 2 由 JMS 消息(由我的软件发送)触发,它应该将消息发送回同一端口上的外部服务器。

在我当前的设置中,我启动了自己的服务器(路由 1)和客户端(路由 2)。我认为这不会起作用,因为两个连接始终处于活动状态。这样,当我想从路由 2 向外部服务器发送消息时,它可能无法连接到外部服务器。但是,当我在路由 1 上收到一条消息时,我可以通过让 inboundInterfaceProcessor.processInterfaceData() 返回将发送到的 String 将消息发送回外部服务器(从绑定到该路由的处理器内部)外部服务器。

因为我能够从路由 1 向外部服务器发送消息,所以我正在考虑从 outboundInterfaceProcessor 触发 inboundInterfaceProcessor 以从路由 2 向外部服务器发送消息。我应该怎么做这个? Camel/Netty 甚至可以做到这一点吗?或者我应该使用其他方法来解决这个问题?

【问题讨论】:

    标签: java apache-camel netty


    【解决方案1】:

    我通过让外部服务器轮询通常通过第二条路由发送的数据来解决这个问题。每条消息都用一个确认消息来回答,所以当入站接口收到这个确认时,我可以检查更多的出接口数据。这并不理想,但它确实有效。 :)

    【讨论】:

      猜你喜欢
      • 2011-02-28
      • 2022-08-08
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 1970-01-01
      • 2014-04-30
      • 2016-02-21
      相关资源
      最近更新 更多