我有一个使用 websocket 进行实时多人游戏的游戏服务器。这是一个 Spring 4 应用程序,我使用 RabbitMQ 作为我的代理。这是我的配置:
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/portfolio">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/queue, /topic"/>
</websocket:message-broker>
通过 4 个客户端的小型测试,我看到 Rabbit 上打开了 4 个连接。
使用 websocket 连接到我的服务器的每个客户端最终是否会打开与代理 (RabbitMQ) 的新连接?这个可以配置吗?
最佳答案
是的,每个 websocket 客户端都有自己的到代理的 TCP 连接。该文档有一个关于 connections to the broker 的部分。 (强调我的):
A STOMP broker relay maintains a single "system" TCP connection to the broker. This connection is used for messages originating from the server-side application only, not for receiving messages. [...]
The STOMP broker relay also creates a separate TCP connection for every connected WebSocket client. [ ... ]
我不知道这是否可以配置,我对 Spring 的这一部分不太熟悉,但我认为应该可以; Spring 是开放的,可以延伸的。我的建议是在 spring-websocket-portfolio 上发布问题项目并询问具体细节。
编辑:OP打开了以下issue关于 spring-websocket-portfolio 项目。
关于spring - Spring 如何管理与 RabbitMQ 的 websocket 连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24671682/