Search code examples
springrabbitmqspring-websocket

How does Spring mange websocket connections to RabbitMQ?


I have a game server that uses websocket for real time multiplayers. It is a Spring 4 application and I use RabbitMQ as my broker. This is my configuration:

<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>

From a very small test with 4 clients I saw 4 connections open on Rabbit.

Does each client that connects to my server using websocket eventually open a new connection to the broker (RabbitMQ)? Can this be configured?


Solution

  • Yes, each websocket client gets its own TCP connection to the broker. The documentation has a section for connections to the broker (emphasis mine):

    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. [ ... ]

    If this can be configured or not I don't know, I'm not all that familiar with this part of Spring, but I assume it should be; Spring is open to extension. My suggestion is to post an issue on the spring-websocket-portfolio project and ask for specifics.

    EDIT : OP opened the following issue on the spring-websocket-portfolio project.