java - Disabling broadcast in SimpMessageTemplate.sentToUser(...) in Spring 4.2.4 -
i trying connect in 2 sessions same spring security user , subscribe same queue using spring 4.2.4. separate messages each session. it's easy using @sendtouser
, seems it's not trivial when using simpmessagingtemplate.sendtouser(...)
- every session receives messages specific other session.
example @sendtouser
:
@controller public class testcontroller { @messagemapping("/queue/hello") @sendtouser(value = "/queue/hello", broadcast = false) public string test() { return integer.tostring(new random().nextint()); } }
example simpmessagingtemplate
:
template.convertandsendtouser("sessionuser{id=123}", "/queue/hello", "test");
i've tried adding sessionid
in headers suggested example in thread: sending-error-message-in-spring-websockets unfortunately not in version of spring. have ideas?
seems setting session id in headers still works, has simpsessionid, not sessionid. assumptions problem lies wrong. summarize, can use overloaded method:
simpmessagingtemplate.convertandsendtouser("sessionuser{id=123}", "/queue/hello", "test", headers);
where headers created by:
private messageheaders createheaders(string sessionid) { simpmessageheaderaccessor headeraccessor = simpmessageheaderaccessor.create(simpmessagetype.message); headeraccessor.setsessionid(sessionid); headeraccessor.setleavemutable(true); return headeraccessor.getmessageheaders(); }
and access simpsessionid should use:
simpmessageheaderaccessor.getsessionid(message.getheaders())
hope useful someone.
Comments
Post a Comment