简体   繁体   English

如何发送TCP请求的回复(spring-integration)?

[英]How to send reply for TCP requests (spring-integration)?

I would need something similar like in Can not send response for UDP message but for TCP. 我需要类似的东西,如无法发送UDP消息响应,但TCP。 So the client send message and TCP server can send back response like OK. 所以客户端发送消息和TCP服务器可以像OK那样发回响应。 For TCP socket-expression="@inbound.socket" and destination-expression="headers['ip_packetAddress']" cannot be used. 对于TCP socket-expression =“@ inbound.socket”和destination-expression =“headers ['ip_packetAddress']”不能使用。

This is how my config look like now: 这就是我的配置现在的样子:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
    xmlns:int-event="http://www.springframework.org/schema/integration/ip"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">

  <int:channel id="tcpSend"/>

  <int-ip:tcp-connection-factory id="client" type="client"/>

  <int-ip:tcp-connection-factory id="server" type="server" host="localhost" port="1234"/>

  <int-ip:tcp-outbound-channel-adapter id="tcpOutbound" channel="tcpSend"
                                   connection-factory="client"/>

  <int-ip:tcp-inbound-channel-adapter id="tcpInbound" channel="tcpReceive"
                                  connection-factory="server"/>

  <int:service-activator id="tcpHandler" input-channel="tcpReceive" output-channel="tcpSend"
                         ref="listener"/>
</beans>

In case of TCP it is much easier because you can use Inbound Gateway . 在TCP的情况下,它更容易,因为您可以使用入站网关

The sample on the matter is in the official repository: https://github.com/spring-projects/spring-integration-samples/tree/master/basic/tcp-client-server 关于此事的样本在官方存储库中: https//github.com/spring-projects/spring-integration-samples/tree/master/basic/tcp-client-server

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM