如何在spring MVC应用程序中插入TCP-IP客户端服务器

 皇家让梦起飞jie 发布于 2023-02-10 15:33

我想知道是否可以在spring mvc应用程序和使用TCP-IP连接的遗留系统之间插入双向连接.

提到遗留系统可以使用TCP/ip而不是http,所以不需要谈论HTTP如何更好,谢谢!

1 个回答
  • 请参阅Spring Integration.您只需使用消息传递网关将SI流连接到MVC控制器即可

    Controller-> gateway - > {optional filtering/transforming} - > tcp outbound gateway

    网关使用其服务接口注入控制器.

    在TCP客户端-服务器示例演示如何.

    编辑:

    如果从样本中不清楚,您需要定义SI流量...

    <!-- Client side -->
    
    <int:gateway id="gw"
        service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
        default-request-channel="input"/>
    
    <int-ip:tcp-connection-factory id="client"
        type="client"
        host="localhost"
        port="1234"
        single-use="true"
        so-timeout="10000"/>
    
    <int:channel id="input" />
    
    <int-ip:tcp-outbound-gateway id="outGateway"
        request-channel="input"
        reply-channel="clientBytes2StringChannel"
        connection-factory="client"
        request-timeout="10000"
        remote-timeout="10000"/>
    
    <int:transformer id="clientBytes2String"
        input-channel="clientBytes2StringChannel"
        expression="new String(payload)"/>
    

    并将Gateway注入您的@Controller...

    public interface SimpleGateway {
    
        public String send(String text);
    
    }
    
    @Controller 
    public class MyController {
    
            @Autowired
            SimpleGateway gw;
    
         ...
    }
    

    2023-02-10 15:35 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有