如何在 Spring MVC 应用程序中插入 TCP-IP 客户端服务器 [英] how to plug a TCP-IP client server in a spring MVC application

查看:50
本文介绍了如何在 Spring MVC 应用程序中插入 TCP-IP 客户端服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wonder if it is possible to plug a bidirectional connection between a spring mvc application and a legacy system working with TCP-IP connections.

如前所述,旧系统使用 TCP/ip 而不是 http,所以无需谈论 HTTP 更好,谢谢!

as mentionned the legacy system works with TCP/ip and not http , so no need to talk about how HTTP is better , thanks !

推荐答案

参见 Spring 集成.您可以使用消息网关将 SI 流简单地连接到您的 MVC 控制器中

See Spring Integration. You can simply wire an SI flow into your MVC controller using a messaging gateway

控制器->网关->{可选过滤/转换}->tcp 出站网关

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

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

The gateway is injected into the controller using its service-interface.

tcp-client-server示例展示了如何.

如果从示例中看不清楚,您需要定义您的 SI 流程...

If it's not clear from the sample, you would need to define your SI flow...

<!-- 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)"/>

并将网关注入您的 @Controller...

and inject the Gateway into your @Controller...

public interface SimpleGateway {

    public String send(String text);

}

@Controller 
public class MyController {

        @Autowired
        SimpleGateway gw;

     ...
}

这篇关于如何在 Spring MVC 应用程序中插入 TCP-IP 客户端服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆