gpt4 book ai didi

spring - TcpSendingMessageHandler 与 TcpReceivingChannelAdapter 协作

转载 作者:可可西里 更新时间:2023-11-01 02:43:25 27 4
gpt4 key购买 nike

在 Spring Integration 中,我使用了几个 channel 适配器来从服务器套接字发送/接收消息。我总是使用以下适配器创建客户端连接:

@Bean
public TcpReceivingChannelAdapter tcpIn(AbstractClientConnectionFactory connectionFactory) throws Exception {
TcpReceivingChannelAdapter receiver = new TcpReceivingChannelAdapter();
receiver.setOutputChannel(fromTcp ());
receiver.setConnectionFactory(connectionFactory);
return receiver;
}

@Bean
@ServiceActivator(inputChannel = "toTcp")
public TcpSendingMessageHandler tcpOut(AbstractClientConnectionFactory connectionFactory) throws Exception {
TcpSendingMessageHandler sender = new TcpSendingMessageHandler();
sender.setConnectionFactory(connectionFactory);
sender.setClientMode(true);
return sender;
}

这里的问题是服务器在同一个套接字中应答远程端口(我打开的套接字端口)。例如,如果我将套接字连接到 127.0.0.1:4444,服务器将响应我打开的端口(使用套接字 tcp 动态)6873 而不是 4444。它使用相同的套接字。

一个快速的答案可能是使用 TcpOutboundGateway 但我在这种情况下有几个问题:

  • 我需要在不考虑的情况下管理连接事件发送/读取操作。例如,我必须自动连接并打开发送任何消息之前的套接字。
  • 根据文档:

for high-volume messages, consider using a collaborating pair of channel adapters. However, you will need to provide collaboration logic.

在大容量场景中,我应该将哪个组件用于请求/响应套接字?

最佳答案

只需阅读 Reference Manual从的话:

To achieve high-volume throughput (avoiding the pitfalls of using gateways as mentioned above) you may consider configuring a pair of collaborating outbound and inbound channel adapters.

另请查看 TCP 多路复用 Sample :

This sample demonstrates how to configure collaborating channel adapters, on both the client and server sides, and one technique for correlating the responses to the corresponding request.

关于spring - TcpSendingMessageHandler 与 TcpReceivingChannelAdapter 协作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39872101/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com