赞
踩
1,@sendToUser
@MessageMapping("/test")
@SendToUser("/topic/test")
public List<JSONObject> addTest(List<JSONObject>){
return list;
}
2,convertAndSendToUser方法
socketMessageTemplate.convertAndSendToUser("userId","/topic/test", sendMessage);
3,以上两种方法在我的需求里都无法实现点对点通信,于是不得不转换了思路,使用如下方法
public void addTest(@Header String token){
socketMessageTemplate.convertAndSend("/topic/test/" + token, sendMessage);
}
通过header注解成功拿到前端传过来的token,订阅地址加上token,使用广播的方式来实现伪单播通信,经测试,可以实现。特此记录
1,Spring Boot系列20 Spring Websocket实现向指定的用户发送消息
2,spring websocket 使用@SendToUser
3,springboot集成websocket点对点推送、广播推送
4,Spring Boot整合WebSocket及Spring Security实例
5,websocket配合spring-security使用token认证
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。