Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-12444

Not able to send message specific to user using STOMP over WebSocket





      I am trying to create a chat app using spring websocket and stomp.
      In this user can send message to each of his/her friends, who are also logged in, by logging into the app.
      For sending message to particular user I take following steps:
      1) User logs in
      2) User subscribes to "/user/queue/messaging" destination. This will be used to send private messages of users to each other.
      3) when user wants to send a message he sends it to destination :


      /queue/messaging where user_id is recipient's user id.
      I am trying to send this from client using STOMP.js send method.
      4) Expected behaviour : now if recipient is logged in and his session id, for example, is DFT0GH then the message in step 3 should be delivered to Queue detination with name messaging-userDFT0GH. Intead of this it is delivered to the same user's queue destination who sent it.

      Please find my example scenario :
      1) User John logs in .
      He subscribes to /user/queue/messaging
      His user id is john
      His session id is ABCD01
      Queue is created with name on activemq broker as
      messaging- userABCD01

      2) User Alice logs in .
      She subscribes to /user/queue/messaging
      His user id is alice
      Her session id is XYZ01
      Queue is created with name on activemq broker as
      messaging- userXYZ01

      3) user John sends a message through STOMP.js send method to Alice
      using destination as "/user/alice/queue/messaging"

      4) now instead of delivering the message to queue
      messaging- UserXYZ01 it gets delivered to John's queue destination i.e
      messaging- userABCD01. Why is it so?

      When i debugged this , I found following line in method
      private DestinationInfo parseUserDestination(Message<?> message) of DefaultUserDestinationResolver class :
      if (SimpMessageType.MESSAGE.equals(messageType)) {
      sessionIds = (sessionId != null ?
      Collections.singleton(sessionId) : this.userSessionRegistry.getSessionIds(user));
      in this sessionId is logged in user's (Principal) sessoin id which is not null as user is logged in and so his sessionIds is returned. and message is delivered to his queue even if intended recipient user is different. when I check usersessionregistry's sessionIds collection i find an entry [alice]:XYZ01. Shouldn't above line return session id of the recipient user instead of logged in user's session id to identify destination queue.?

      Sorry I am trying this for the first time. So Please let me know if I miss anything here and of there is
      1) any way to satisfy my use case
      2) or my use case itself is invalid.

      Thanks in advance.


          Issue Links



              bclozel Brian Clozel
              ShaileshV Shailesh Vaishampayan
              Last updater:
              Spring Issuemaster
              0 Vote for this issue
              5 Start watching this issue


                Days since last comment:
                1 year, 25 weeks, 2 days ago