11

I'm using Spring 4.2 websockets with stomp on the serverside. Client uses stomp.js. I noticed that it is possible for a user to subscribe the same topic-destination multiple times. When a message is delivered to this destination, the user receives it multiple times too.

  1. Why is this possible? What would be a use case for this?
  2. How can I avoid it? The @SubscribeMapping is called AFTER the subscription and I cannot cancel it.
Ickbinet
  • 277
  • 3
  • 12
  • 3
    I would advise using your unique identifier for your user as the subscription ID when subscribing to a topic/destination using stomp JS. This prevents the autogeneration of subscriptionIds on each subscribe to the topic so you will only have one subscription per topic per user session: `function subscribe(destination, accountId, callbackHandler) { if (null !== stompClient) { stompClient.subscribe(destination, function(message) { callbackHandler(message); }, {id: accountId}); } }` – steviemo Apr 04 '17 at 15:25
  • 2
    (7 years later) why couldn't this be prevented in the client? – mowwwalker Jun 09 '22 at 15:36

0 Answers0