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

@SubscribeMapping semantics #28

Closed
cloudmark opened this issue Mar 1, 2014 · 5 comments
Closed

@SubscribeMapping semantics #28

cloudmark opened this issue Mar 1, 2014 · 5 comments

Comments

@cloudmark
Copy link

In the example, when a client subscribes to /app/positions the PortfolioController#getPositions method is invoked and the user on a specific session receives a list of positions.

After this invocation is the destination /app/positions of any use?

My understanding is that the @SubscribeMapping annotation should be used in situations when a reply to a user with a specific session is essential. After this initial reply is sent to the client, the client should then subscribe to a user queue (/user/queue/position-updates) in order to receive further updates (not session specific).

Is this understanding correct? Is there any other way how to provide the push/reply a message to user on a particular session semantics other than the one I just described?

@rstoyanchev
Copy link
Owner

Both destinations are for messages to a specific user/session.

The difference is that with @SubscribeMapping("/app/positions"), data is returned directly to the client without ever passing through the message broker, which the means the subscription is not remembered. It's a one time request-reply exchange and that makes sense given the use case, i.e. initial loading of portfolio positions.

On the other hand, /user/queue/position-updates will be translated to /queue/position-updates-{userSessionSuffix} (by UserDestinationMessageHandler). The subscription will then be processed and registered with the message broker. Subsequently many messages (position updates) can be sent through that subscription by sending messages to the broker at /user/{username}/position-updates.

@cloudmark
Copy link
Author

Thanks for your clarification.

From what I'm understanding, given the user has two tabs open and the client sends a message to the server from tab 1, it is impossible to send a message to a specific client connection (tab 1). Using the @SendToUser("/queue/position-updates") annotation will push the message to both user sessions.

Is there something fundamentally wrong in trying to reply to a specific user web session? Is Ajax the preferred in this case?

@rstoyanchev
Copy link
Owner

Indeed currently an @SendToUser annotation on a controller will result in a message sent to all user sessions found. This is the simplest behavior and arguably not a bad default. Of course it is entirely possibly to imagine a use case where a message should be sent only to one session and appear in only one tab in the browser.

When using @SendToUser on a controller, we can send a message only to the session associated with the input message to which we are responding. That could be enabled through an additional boolean attribute on the annotation. Feel free to open a request in JIRA for this by the way and if possible please describe a use case to keep in mind.

However, when using SimpMessagingTemplate.sendToUser there is no way I can see of identifying a specific session to send the message to. I guess here it's important to consider specific use cases. For example can all tabs receive the message but filter out what they don't need?

@cloudmark
Copy link
Author

JIRA issue opened - https://jira.springsource.org/browse/SPR-11506. I posted an initial fix, and posted it as a comment on JIRA. We can continue the discussion over there.

@rstoyanchev
Copy link
Owner

Okay thanks for that and I've set the fix version so I'm closing this ticket here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants