Requisites:
I'm using collaborating TcpReceivingChannelAdapter and TcpSendingMessageHandler with TcpNetClientConnectionFactory.
And IntegrationFlow for generating those connections dynamically.
How to create multiple sockets for TcpNetClientConnectionFactory that all point to the same Host and port?
I know how to set destination with new TcpNetClientConnectionFactory(host, port). But I'm unable to see or find how to affect which port is used
Should it be done with multiple TcpNetClientConnectionFactory each being bound to one inbound and outbound TCP adapter?
How can I set the local port for those connections? or at least how to obtain it?
I don't seem to find any documentantion about this option. The most similar would be This question
You need a separate connection factory/adapters for each.
Use an ApplicationListener
or @EventListener
to receive TcpConnectionEvent
s.
The event has getConnectionId()
which contains both the local and remote port; the event also has the connection factory bean name.
Or you can cast getSource()
to TcpConnection
and call getPort()
(but you should not otherwise interact with the TcpConnection
object.