【发布时间】:2021-01-22 12:54:35
【问题描述】:
是否可以设置一个可以同时连接到多个 TCP 服务器的动态 TCP 客户端? 我正在使用带有 dsl 配置的 spring 集成。我已经阅读了有关此主题的其他一些问题,但无法找到使其发挥作用的方法。
我用来设置单个连接的配置如下:
@Configuration
public class TcpAsyncConfig {
MessageHandler handler = new MessageHandler();
@Bean
public AbstractClientConnectionFactory client1() {
return Tcp.netClient("localhost", 6050)
.leaveOpen(true)
.soKeepAlive(true)
.singleUseConnections(true)
.deserializer(new CustomSerializerDeserializer())
.get();
}
@Bean
public IntegrationFlow client1Out(AbstractClientConnectionFactory client1) {
return IntegrationFlows.from(RobotGateways.class)
.handle(Tcp.outboundAdapter(client1))
.get();
}
@Bean
public IntegrationFlow client1In(AbstractClientConnectionFactory client1) {
return IntegrationFlows.from(Tcp.inboundAdapter(client1))
.transform(Transformers.objectToString())
.log(msg -> "client1: " + msg.getPayload())
.handle(handler::handleMessage)
.get();
}
@Bean
@DependsOn("client1Out")
public RobotGateways robotGateways(RobotGateways gateways){
return gateways;
}
}
所以我想创建一个连接列表并使用网关在特定连接上发送消息。
【问题讨论】: