【发布时间】: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