1

I have a task to create a Spring-integration TCP client which should connect to a server and receive messages from it:

  • The server is responsible for sending "heartbeat" and data messages and doesn't expect any incoming messages from the client, except acknowledgements.
  • The client must open and maintain (reopen) a connection to the server.

As I understand, TcpNetClientConnectionFactory opens a connection only upon sending a message. Is there any way to open a connection without sending any data (something like SocketFactory.createSocket(host, port) does) and maintain it?

Sergey
  • 13
  • 4

1 Answers1

0

Please, investigate a TcpReceivingChannelAdapter and let us know why it doesn't work for you:

https://docs.spring.io/spring-integration/docs/current/reference/html/ip.html#tcp-adapters

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Set `clientMode=true` on the sending adapter - see the documentation @artem pointed you to `>For an outbound adapter, the connection is normally established when the first message is sent. The client-mode="true" on an outbound adapter causes the connection to be established when the adapter is started. By default, adapters are automatically started. Again, the connection factory must be of type client and have single-use="false". A retry-interval and scheduler are also supported. If a connection fails, it is re-established either by the scheduler or when the next message is sent.` – Gary Russell Jan 26 '21 at 15:30
  • Thanks a lot, guys! Everything works fine now. – Sergey Jan 27 '21 at 06:05