How to make TCP client which send request and receive response .Also accepts the messages pushed from server

为君一笑 提交于 2019-12-25 00:13:35

问题


I have to create a tcp client

1)-which will send request msg to server and receive response for it

2)- Some time the server push msg to the client without any request from clientSo client should accept and read it .

So I have already asked the question for the 1 part of it My tcp client using spring integration not able to get response and tried to reach some solution .But for second part i am confused what to use tcpoutbound gateway or inboundgateway with client flag enable. Kindly suggest any examples or confiuration should I do to read messages pushed by server.

P.s I am new to SI


回答1:


You can't use gateways; they are for simple request/reply scenarios.

For arbitrary messaging between peers, refer to the section on Collaborating Channel Adapters.

To achieve high-volume throughput (avoiding the pitfalls of using gateways as mentioned above) you may consider configuring a pair of collaborating outbound and inbound channel adapters. Collaborating adapters can also be used (server-side or client-side) for totally asynchronous communication (rather than with request/reply semantics). On the server side, message correlation is automatically handled by the adapters because the inbound adapter adds a header allowing the outbound adapter to determine which connection to use to send the reply message.

On the server side, care must be taken to populate the ip_connectionId header because it is used to correlate the message to a connection. Messages that originate at the inbound adapter will automatically have the header set. If you wish to construct other messages to send, you will need to set the header. The header value can be captured from an incoming message.

On the client side, the application will have to provide its own correlation logic, if needed. This can be done in a number of ways. ...



来源:https://stackoverflow.com/questions/44551952/how-to-make-tcp-client-which-send-request-and-receive-response-also-accepts-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!