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
Enable use of both @SendTo and @SendToUser on the same method [SPR-16891] #21430
Comments
Stéphane Nicoll commented FWIW |
Ethan Mcgee commented I realized this after I started authoring the changes for the pull request. I've amended the description with what I actually wound up doing which was a bit simpler than the original proposal and doesn't break backwards compatibility. |
Rossen Stoyanchev commented The resulting syntax creates a lot of noise. Return values were only ever meant to fit the more common cases. For anything more advanced, just use @MessageMapping("/document.save.{id}")
public void save(@Payload Document document, @DestinationVariable Long id) {
Document doc = documentService.storeDocument(document);
template.convertAndSendToUser("usr", "/topic/document.save.complete." + id, doc);
template.convertAndSend("/topic/document.updated", doc);
} |
Ethan Mcgee commented My only issue with that is that there is a fair amount of logic embedded in the annotations for capturing the username and session to allow sendToUser to work as expected without having to inject the Message as a parameter. I like the simplicity afforded by the annotations as it means not having to inject additional parameters. It also means letting spring continue handling capturing the session and user without having to duplicate that logic into a service. Another way of accomplishing this request without resorting to a wrapper annotation would be to allow the |
Rossen Stoyanchev commented The sessionId shouldn't be required in most cases, and in that sense infrastructure code like That said allowing the use of both |
Ethan Mcgee commented Allowing only one I'll update my pull request so that |
Rossen Stoyanchev commented Okay thanks. |
Ethan Mcgee commented Pull request updated. |
Rossen Stoyanchev commented Thanks for the quick update, but looking at #18811 I'm not sure we can go ahead with this after all, since a method-level That said, as I mentioned initially, the design idea for Also not to forget, a controller method can use |
Ethan Mcgee commented Having the SimpMessagingTemplate know about the message (injected or passed as a parameter) would be nice. Then all of the pieces around whether to use the username or sessionId could be hidden and that logic wouldn't have to be duplicated into a service in the application. Right now, to send a message to a user, I'm having to duplicate the logic in the SendToMethodReturnValueHandler around capturing the sessionId and user. It works, but it is a hack. |
Rossen Stoyanchev commented
I don't think that's fair statement by any measure. The logic in SendToMethodReturnValueHandler is more complicated because it deals with class and method annotations and covers all possible declarative scenarios. By contrast a controller method uses the SimpMessagingTemplate directly and should be 1-2 lines max. The two possible complications are having to inject the user and session id. Can you confirm that you're using session id for a specific reason? It should not be required in any authenticated scenario where the |
Ethan Mcgee commented Meh, it feels like duplication and a hack because the annotations already provide that functionality. I'll just stick with using It would still be nicer, imo, to be able to do it all via annotations since the annotations encapsulate everything, but that is just me being picky. |
Rossen Stoyanchev commented We'll go ahead with this after all. We will not change the override semantics, but we'll allow both on the method level. |
Rossen Stoyanchev commented
|
Ethan Mcgee opened SPR-16891 and commented
It would be really nice if it were possible using spring messaging to return an individual message to both the user and simultaneously broadcast that message to everyone on different queues. The user component could react to the personal message while other components on the page could react to the global message.
With this in mind, my proposal is that a wrapper annotation be added that allows multiple
@SendTo
and@SendToUser
annotations to be applied. Then if that annotation is present, each annotation is added individually.An example of what I am proposing is below.
Affects: 5.0.6
Issue Links:
@SendToUser
overrides@SendTo
on methodReferenced from: pull request #1846, and commits f4bffea
The text was updated successfully, but these errors were encountered: