Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to send message specific to user using STOMP over WebSocket [SPR-12444] #17049

Closed
spring-issuemaster opened this issue Nov 16, 2014 · 11 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Nov 16, 2014

Shailesh Vaishampayan opened SPR-12444 and commented

Hi,

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 :
    /user/{user_id}/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.


Affects: 4.1.1

Reference URL: http://stackoverflow.com/questions/26967034/not-able-to-send-message-specific-to-user-using-spring-websocket-stomp

Issue Links:

  • #16131 @SendToUser should provide a single session reply mode

Referenced from: commits 75c70fa

0 votes, 5 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 17, 2014

Shailesh Vaishampayan commented

Hi Brian,
I know today only you assigned the issue and I understand you might be having deadlines as well .
Actually this is a blocker for my scenario and the app as I am not able to send the private messages targeted at specific user. Can you please let me know if this is the real issue and if yes how can I temporarily put a fix for my own app like extending or in very dirty way :just modifying the source file and repackaging th JAR?

Thanks,
Shailesh.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 17, 2014

Shailesh Vaishampayan commented

Another thing I found out : in 4.0.8 above line I mentioned in org.springframework.messaging.simp.user.DefaultUserDestinationResolver looks like
sessionIds = this.userSessionRegistry.getSessionIds(user);

instead of
sessionIds = (sessionId != null ? Collections.singleton(sessionId) : this.userSessionRegistry.getSessionIds(user));

Ofcourse you guys know better. seems to have been committed in 4.1.0

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 17, 2014

Brian Clozel commented

Hi ShaileshV
Is this a regression (i.e. did it work in a previous version)?

If you could come up with a minimal repro project, that'd be great.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 17, 2014

Shailesh Vaishampayan commented

I guess yes. I couldn't revert to older version (4.0.8). However what i did is

  1. I changed the source file(DefaultUserDestinationResolver.java) by copying it to my eclipse workspace and reverted the following line :
    sessionIds = (sessionId != null ? Collections.singleton(sessionId) : this.userSessionRegistry.getSessionIds(user));
    to
    sessionIds = this.userSessionRegistry.getSessionIds(user); (BTW this was the exact line i found in version 4.0.8)

  2. copied back the generated class files into the existing JAR. and yes it started working and delivered the messages to the right queue.

I will try to create a minimal project. However above code change definitely proved that it was working with 4.0.8. Actually can't revert to 4.0.8 as because of some additional classes added in 4.1.1 and it starts breaking.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 18, 2014

Brian Clozel commented

Hi ShaileshV - don't bother submitting a repro project.
I think I got it reproduced in a unit test, thanks to your very detailed comments. I'll keep you updated in this thread.

Thanks!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 18, 2014

Shailesh Vaishampayan commented

Thanks Brian. Waiting for the next release with fix!!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 21, 2014

Brian Clozel commented

ShaileshV The fix is in master, you should be able to test it in your application in a few minutes:

  • using version 4.1.3.BUILD-SNAPSHOT
  • from the snapshot repository http://repo.spring.io/libs-snapshot/
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 21, 2014

Shailesh Vaishampayan commented

Sure Brian I will test this and update this. Am I supposed to Close this issue once I verify the fix? Just asking as using JIRA for first time.
If so I will take some time as this week I am busy in my exams.
Thanks for the quick response though.

Thanks,
Shailesh.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 21, 2014

Brian Clozel commented

You don't have to close the issue, we'll do it when the fix ships with the next release.
Don't worry about testing this, I took care of it (and I'll do some more before the release) - I gave you that info in case you wanted to prepare an application for the next upgrade.

Good luck with your exams!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 22, 2014

Shailesh Vaishampayan commented

Alright Brian. Thanks for the wishes!!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Dec 7, 2016

bbwang commented

in which way you finally resolved this issue,can i share your experience,i am a man Living i China,and i have exhausted in spring stomp websocket.thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.