处理回复 GenericMessage 时未找到连接

问题描述

尝试使用 spring-integration-ip 设置 Spring Boot TCP Server,但是当向服务器发送消息时总是收到错误消息:

var deptSecretaryInitial = new InitialHere
        {
            AnchorString = "Dept Secretary Initials",AnchorUnits = "pixels",AnchorYOffset = "50"
        };

        var newAdvisorNameForSec = new Text
        {
            AnchorString = "(Dept Secretary) New Advisor:",AnchorYOffset = "-135",TabLabel = "NewAdvisorNameForSec",Height = "25",Width = "250",ConditionalParentLabel = "NewAdvisorNameForChair",ConditionalParentValue = "on",Tooltip = "Secretary"
        };

        var newAdvisorIdForSec = new Text
        {
            AnchorString = "Adviser Id:",AnchorYOffset = "120",TabLabel = "NewAdvisorBannerIdForSec",Width = "100",ConditionalParentLabel = "NewAdvisorBannerIdForChair",Tooltip = "Secretary 2"
        };

        var deptSecretaryTabs = new Tabs
        {
            TextTabs = new List<Text>{newAdvisorNameForChair,newAdvisorIdForChair,newAdvisorNameForSec,newAdvisorIdForSec},InitialHereTabs = new List<InitialHere>{deptSecretaryInitial}
        };

这是我的 TcpserverConfig 文件

2021-06-03 23:58:36.916 ERROR 35752 --- [pool-1-thread-4] o.s.i.ip.tcp.TcpInboundGateway           : Connection not found when processing reply Genericmessage [payload=byte[5],headers={ip_tcp_remotePort=51436,ip_connectionId=localhost:51436:10001:dbc9ca03-a509-4a66-9bbd-020478794bbd,ip_localInetAddress=/0:0:0:0:0:0:0:1,ip_address=0:0:0:0:0:0:0:1,id=3c446dc8-f417-e387-a4e4-42c023da0d4f,ip_hostname=localhost,timestamp=1622746716916}] for Genericmessage [payload=byte[3],id=59caa1c3-20df-57c0-d1dc-81c2b0adfe0d,timestamp=1622746716916}]

和 TcpserverEnpoint 文件

@Configuration
@EnableIntegration
public class TcpserverConfig {

    @Value("${tcp.server.port}")
    private int port;

    @Bean
    public AbstractServerConnectionFactory serverConnectionFactory() {
        TcpNioServerConnectionFactory serverConnectionFactory = new TcpNioServerConnectionFactory(port);
        serverConnectionFactory.setUsingDirectBuffers(true);
        return serverConnectionFactory;
    }

    @Bean
    public MessageChannel inboundChannel() {
        return new DirectChannel();
    }

    @Bean
    public TcpInboundGateway inboundGateway(AbstractServerConnectionFactory serverConnectionFactory,MessageChannel inboundChannel) {
        TcpInboundGateway tcpInboundGateway = new TcpInboundGateway();
        tcpInboundGateway.setConnectionFactory(serverConnectionFactory);
        tcpInboundGateway.setRequestChannel(inboundChannel);
        return tcpInboundGateway;
    }
}

我正在尝试发出简单的请求 -> 响应 TCP 服务器。发送消息后,它会在调试控制台中打印出来,但也会抛出错误

解决方法

这是我为您准备的:

@SpringBootApplication
public class So67827589Application {

    public static void main(String[] args) {
        SpringApplication.run(So67827589Application.class,args);
    }

    @Bean
    public AbstractServerConnectionFactory serverConnectionFactory() {
        TcpNioServerConnectionFactory serverConnectionFactory = new TcpNioServerConnectionFactory(7777);
        serverConnectionFactory.setUsingDirectBuffers(true);
        return serverConnectionFactory;
    }

    @Bean
    public MessageChannel inboundChannel() {
        return new DirectChannel();
    }

    @Bean
    public TcpInboundGateway inboundGateway(AbstractServerConnectionFactory serverConnectionFactory,MessageChannel inboundChannel) {

        TcpInboundGateway tcpInboundGateway = new TcpInboundGateway();
        tcpInboundGateway.setConnectionFactory(serverConnectionFactory);
        tcpInboundGateway.setRequestChannel(inboundChannel);
        return tcpInboundGateway;
    }

    @ServiceActivator(inputChannel = "inboundChannel")
    public byte[] process(byte[] message) {
        System.out.println(Arrays.toString(message));
        return "Hello".getBytes();
    }

}

然后我去命令行执行:

telnet localhost 7777

然后输入任何内容并返回 Hello。然后我可以输入越来越多的内容 - 然后 Hello 回到我身边。永远!

所以,一切都按预期进行。 Spring Boot 2.5.0

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...