1
votes

I know spring integration has TcpInboundGateway, TcpOutboundGateway and ByteArrayLengthHeaderSerializer to handle data coming through TCP port.

ByteArrayLengthHeaderSerializer works great if the TCP server needs to read all the data sent from the client and then processes it. (request and response model)

For example if the client sends 9AAPL then Server can send the AAPL price.

I am looking for a way where the client can interact with the server without closing the connection in multiple requests.

For example: if the client sends 9AAPL then the server should send AAPL price and wait for another request from the client without closing connection. This interaction can go on till the client sends 5 or no response from a client in 50 seconds.

can you please suggest the spring integration classes (TCP Gateways, Serializers etc.) that needs to be used for this interactive behavior?

we are using spring integration 4.2.6.RELEASE version and java 8. Are those versions good enough or do we need to upgrade to newer versions?

UPDATE: Here is my spring configuration:

    <bean id="connectionSerializeDeserialize" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer"/>

    <int-ip:tcp-inbound-gateway id="gatewayCrLf"
        connection-factory="crLfServer"
        request-channel="serverBytes2StringChannel"
        error-channel="errorChannel"
        reply-timeout="10000"/> <!-- reply-timeout works on inbound-gateway -->

    <int:channel id="toSA" />

    <int:service-activator input-channel="toSA"
        ref="myService"
        method="prepare"/>

    <int:object-to-string-transformer id="serverBytes2String"
        input-channel="serverBytes2StringChannel"
        output-channel="toSA"/>

    <int:transformer id="errorHandler"
        input-channel="errorChannel"
        expression="payload.failedMessage.payload + ':' + payload.cause.message"/>

Thanks

1

1 Answers

1
votes

Please show your configuration - what you want is the default behavior.

Only if you set singleUse to true will the gateway close the socket.

Of course, your client must not close the socket either.

Set the soTimeout to close the socket after receiving no requests for that time.

You don't need newer versions, but we always recommend using the latest (4.3.4).