【发布时间】:2021-06-03 19:24:45
【问题描述】:
尝试使用 spring-integration-ip 设置 Spring Boot TCP Server,但是当向服务器发送消息时总是得到错误消息:
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], 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=59caa1c3-20df-57c0-d1dc-81c2b0adfe0d, ip_hostname=localhost, timestamp=1622746716916}]
这是我的 TcpServerConfig 文件:
@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;
}
}
和 TcpServerEnpoint 文件:
@Component
@MessageEndpoint
public class TcpServerEndpoint {
@ServiceActivator(inputChannel = "inboundChannel")
public byte[] process(byte[] message) {
System.out.println(Arrays.toString(message));
return "Hello".getBytes();
}
}
我正在尝试发出简单的请求 -> 响应 TCP 服务器。发送消息后,它会在调试控制台中打印出来,但也会引发错误。
【问题讨论】:
-
有没有机会让你的那个简单的 Spring Boot 项目在我们这边玩和复制?
-
这是一个简单的tcp服务器,只有2个文件和maven依赖列表中的spring-integration-ip。就是这样。
-
好吧,但您展示的内容仍然必须开箱即用。如果没有,那就有问题了。因此,如果我们在同一环境中调查问题,那就太好了。例如:你如何测试这个解决方案真的很重要。感谢理解。
-
@ArtemBilan 项目很简单,OS是MacOS,放到GitHub上github.com/RussellSk/spring-tcp-server
-
我尝试将我的 Netty 项目移动到 spring-integration-ip。感谢您的帮助,我知道问题可能出在序列化器和反序列化器中,但不知道该怎么办。我在 Netty 项目中使用此命令并尝试使用 spring-integration-ip 来实现它,命令示例:echo -ne "\x01\x02" |数控本地主机 8080 | hexdump -v -e "%02X"
标签: java spring-boot spring-integration spring-integration-ip