I'm using Spring 4.3.5 and WebSocket with SockJS, STOMP and SimpleBrokerMessageHandler.
In my application I have three separate WebSocket endpoints running on a different address: /endPointA, /ednpointB, /endpointC To be even more specific, I have three separate configuration classes annotated with @Configuration @EnableWebSocketMessageBroker annotations.
I also have a Class that has @Autowired SimpMessagingTemplate.
Finally I have three clients, each connected to one, different EndPoint. All of them, however are subscribed to the "same" channel address which is /topic/messages
- ClientOne is connected endpointA
- ClientTwo is connected endpointB
- ClientThree is connected endpointC
When I use SimpMessagingTemplate to send something to /topic/messages, then all clients receives this message.
After that I have two questions:
- Is there a way to "isolate" the web Socket endpoints so the message will not be propagated to all endpoints?
- Why is this actually happening here?
I did some investigation (heap dump analysis) and I found that for my configuration I have:
- Three instances of SimpMessagingTemplate, However I'm using always the same one instance to send a message (because of @Autowire - additionaly I'm printing SimpMessagingTemplate.toString()).
- One instance of SimpleBrokerMessageHandler
- Three instances of SockJsWebSocketHandler
So I wonder, if this message propagation over all endpoits is a "feature" of SimpleBrokerMessageHandler or SimpMessagingTemplate.