I am trying to connect in two sessions with the same Spring Security user and subscribe to the same queue using Spring 4.2.4. I would like to get separate messages for each session. It's easy to do using @SendToUser
, but seems that it's not so trivial when using SimpMessagingTemplate.sendToUser(...)
- every session receives all messages that are specific to other session.
Example for @SendToUser
:
@Controller
public class TestController {
@MessageMapping("/queue/hello")
@SendToUser(value = "/queue/hello", broadcast = false)
public String test() {
return Integer.toString(new Random().nextInt());
}
}
Example for SimpMessagingTemplate
:
template.convertAndSendToUser("SessionUser{id=123}", "/queue/hello", "test");
I've tried adding sessionId
in headers as suggested for example in this thread:
sending-error-message-in-spring-websockets
Unfortunately it does not help in this version of Spring.
Does anyone have any ideas?