Search code examples
spring-integrationspring-integration-ip

Send unsolicited message to Spring TcpInboundGateway


I'm writing an IntegrationFlow using TcpInboundGateway. When the client connects and builds a connection to the server (inbound gateway), is there a way to send 'server initiated message' to that connection? I already know how to send 'reply' for incoming messages.

I have read that inbound gateway can configured with unsolicited message channel but cannot find relevant setter method in TcpInboundGateway class.

Starting with version 5.4, the inbound can be configured with an unsolicitedMessageChannel. Unsolicited inbound messages will be sent to this channel, as well as late replies (where the client timed out). To support this on the server side, you can now register multiple TcpSender s with the connection factory. Gateways and Channel Adapters automatically register themselves. When sending unsolicited messages from the server, you must add the appropriate IpHeaders.CONNECTION_ID to the messages sent.

To do this, do I need to make a use of TcpOutboundGateway together?


Solution

  • For server initiated messaging it is recommended to use a combination of TcpReceivingChannelAdapter and TcpSendingMessageHandler on the client side. See some information in the docs: https://docs.spring.io/spring-integration/docs/current/reference/html/ip.html#ip-collaborating-adapters