How to dynamically assign port and host name for TcpNetClientConnectionFactory without bean

Viewed 18

I'm able to make a TCP client connection to a server with static hostname and portNumber by creating a bean of ClientConnectionFactory and TcpOutboundGateway.

But I have a scenario where I'm suppose to deal with multiple TCP connections with different Hostname and PortNumber. I have tried multiple ways but facing errors. Can anyone suggest best approach to handle this ?

@Bean
@ServiceActivator(inputChannel = "toOutgate")
public TcpOutboundGateway outGate(AbstractClientConnectionFactory cf) {
    TcpOutboundGateway gate = new TcpOutboundGateway();
    gate.setConnectionFactory(cf);
    gate.setOutputChannelName("byteToString");
    gate.setRequiresReply(true);
    gate.setRequestTimeout(60000);
    gate.setRemoteTimeout(60000);
    return gate;
}

@Bean
public AbstractClientConnectionFactory clientCF() {
        TcpNetClientConnectionFactory tcpNet = new TcpNetClientConnectionFactory("localhost", 4000);
        tcpNet.setDeserializer(omeonCodec());
        tcpNet.setSerializer(omeonCodec());
        return tcpNet;
    }
0 Answers
Related