Spring integration Spring在路由inputChannel第一个通道时总是错误的
我正在使用Spring integration Spring在路由inputChannel第一个通道时总是错误的,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我正在使用 spring-integration-java-dsl-1.2.3.RELEASE spring-integration-ip-4.3.17.1版本 spring-integration-http-4.3.17.RELEASE 给定此代码以动态生成TCP连接。我定义了Reveiver适配器和SenderAdapter IntegrationFlow ifr = existsConnection(connectionId); if (ifr == null) {
- spring-integration-java-dsl-1.2.3.RELEASE
- spring-integration-ip-4.3.17.1版本
- spring-integration-http-4.3.17.RELEASE
IntegrationFlow ifr = existsConnection(connectionId);
if (ifr == null) {
TcpNetClientConnectionFactory cf = new TcpNetClientConnectionFactory(host, port);
final ByteArrayLengthHeaderSerializer by = new ByteArrayLengthHeaderSerializer(headBytes);
cf.setSingleUse(false);
cf.setSoKeepAlive(true);
cf.setSerializer(by);
cf.setDeserializer(by);
cf.setComponentName(connectionId);
//Inbound Adapter
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(cf);
adapter.setClientMode(true);
adapter.setErrorChannelName("errorChannel");
adapter.setRetryInterval(retryInterval);
adapter.setOutputChannel(bme.fromTcp());
//OutBound Adapter
TcpSendingMessageHandler sender = new TcpSendingMessageHandler();
sender.setConnectionFactory(cf);
ifr = IntegrationFlows.from(adapter)
.enrichHeaders(h -> h.header("connectionId",connectionId))
.handle(sender).get();
this.flowContext.registration(ifr).id(connectionId+CONNECTION_SUFFIX).addBean(cf).register();
当我第一次尝试重新路由到正确的通道时,我得到的是“fromTcp”,而不是发送方适配器,当我从IntegrationFlow.getInputChannel()恢复通道时,我认为您在某个地方为该
bme.fromTcp()
多了一个订户,因此在流中,您可以通过.enrichHeaders()获得一个订户
我猜TCP中的是一个直接频道
,默认情况下基于RoundRobinLoadBalancing策略
,因此传入的消息在订阅者之间是平衡的
不确定您的意图,但是考虑不要将该<代码> BME。FROXTCP()/java代码输入到<代码> TCP收发器通道适配器< /C>中,Java DSL将关心从<适配器> <适配器> >代码> >
我不明白你用.enrichHeaders()这么说是什么意思,我得到了更多的支持。我想用.enrichHeaders()做的是,当我通过directChannel(从TCP)发送消息时,添加一个名为“connectionId”的头。你能给我一些建议怎么做或者用不同的方式做吗?