如何仅从服务器向特定用户发送websocket消息?
我的webapp具有弹簧安全设置并使用websocket.我遇到了一个棘手的问题,试图只从服务器向特定用户发送消息.
我阅读本手册的理解来自我们可以做的服务器
simpMessagingTemplate.convertAndSend("/user/{username}/reply", reply);
Run Code Online (Sandbox Code Playgroud)
在客户端:
stompClient.subscribe('/user/reply', handler);
Run Code Online (Sandbox Code Playgroud)
但我永远无法调用订阅回调.我尝试了许多不同的路径,但没有运气.
如果我将它发送到/ topic/reply它可以工作,但所有其他连接的用户也会收到它.
为了说明问题,我在github上创建了这个小项目:https://github.com/gerrytan/wsproblem
重现步骤:
1)克隆并构建项目(确保您使用的是jdk 1.7和maven 3.1)
$ git clone https://github.com/gerrytan/wsproblem.git
$ cd wsproblem
$ mvn jetty:run
Run Code Online (Sandbox Code Playgroud)
2)导航到http://localhost:8080,使用bob/test或jim/test登录
3)单击"请求用户特定消息".预期:仅对此用户的"仅收到消息给我"旁边显示消息"hello {username}",实际:未收到任何消息