gpt4 book ai didi

java - 如何在 spring-integration tcp 网关中实现粘性 session ?

转载 作者:行者123 更新时间:2023-11-29 04:06:11 25 4
gpt4 key购买 nike

我目前正在使用 spring 集成开发一个 tcp 套接字服务器。到目前为止,我有下面提到的代码。但是有可能对该套接字服务器的多个节点进行负载平衡。为此,我需要有可以在节点之间共享的套接字连接上下文的固定 session 。谁能提出可能的解决方案?

@Bean
public IntegrationFlow listnerServerFlow(
TcpNetServerConnectionFactory serverConnectionFactory,
DeviceListenerService deviceListenerService) {
return IntegrationFlows
.from(Tcp.inboundGateway(serverConnectionFactory))
.handle(deviceListenerService::processRequest)
.get();
}

@Bean
public TcpNetServerConnectionFactory serverConnectionFactory() {
TcpNetServerConnectionFactory connectionFactory = new TcpNetServerConnectionFactory(2424);
connectionFactory.setSerializer(new ByteArrayCrLfSerializer());
connectionFactory.setDeserializer(new ByteArrayCrLfSerializer());
connectionFactory.setSingleUse(false);
connectionFactory.setSoKeepAlive(true);
return connectionFactory;
}

最佳答案

一般情况下,您可以在请求中添加唯一标识符,并将 session 数据存储在单独的 Redis 中。

无论哪个节点正在处理请求,该节点都可以根据请求中的标识符从 Redis 中检索 session 数据。

希望这可以帮助您找到解决方案。

关于java - 如何在 spring-integration tcp 网关中实现粘性 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58536708/

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