Can't send user specific message using Spring Websocket STOMP

I am trying to create a chat app using spring websocket and stomp.
I am using spring 4.1.1, Stomp.js, ActiveMQ 5.9
In this case, the user can send a message to each of his friends who are also logged in by logging into the application. To send a message to a specific user, I do the following steps:
 1) User logs in
 2) The user subscribes to the destination "/ user / queue / messaging".
    This will be used to send users' private messages to each other.
 3) when the user wants to send a message, he sends it to the destination:
    / user / {user_id} / queue / messaging, where user_id is the user ID of the recipients.
    I am trying to send this from a client using the STOMP.js submit method.
 4) Expected Behavior: Now if the recipient is registered and his session id, for example, is DFT0GH, then the message in step e should be delivered to the destination of the queue named messaging-userDFT0GH. Instead, it is delivered to the same destination address of the user who sent it.

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

2) Login of user Alice. She subscribes to / user / queue / messaging / His user id is alice
  Her session id is XYZ01 A
  queue is created with a name in the activemq broker as messaging-userXYZ01

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

4) instead of delivering the message to the messaging-UserXYZ01 queue, it is delivered to John's destination ie messaging-userABCD01. Why is this so?

When I debug this, I found the following line in the private DestinationInfo parseUserDestination (Message message) method of the DefaultUserDestinationResolver class:

  if (SimpMessageType.MESSAGE.equals(messageType)) {
        ........
    sessionIds = (sessionId != null ?
                Collections.singleton(sessionId) : this.userSessionRegistry.getSessionIds(user));      
    }

      

This sessionId registers the session ID of the user (principal), which is not null when the user logs on and so his sessionIds is returned and the message is delivered to his queue even if the intended recipient user is different.
When I check the sessionessionistry sessionIds account, I find the entry [alice]: XYZ01.
Should not exceed the line session ID if the user identifies the destination queue instead of logging into the user session.?

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

Thanks in advance.

+3


source to share


1 answer


It's just that this question remains unanswered - this is indeed a bug, and you raised it as SPR-12444 .

This will be fixed in Spring Framework 4.1.3.



As a side note, I would like to point out that if you are deploying an application with multiple instances, session registries are not shared between instances by default - so this will cause problems when sending a message from alice (with session to server # 1) to bob (session to server # 2).

+2


source







All Articles