Spring websocket 使用Spring Websocket在目标主题中设置principal.getName()
我使用的是SpringWebSocket,我不知道如何将消息发送到包含用户名的特定分区 i、 e:Spring websocket 使用Spring Websocket在目标主题中设置principal.getName(),spring-websocket,Spring Websocket,我使用的是SpringWebSocket,我不知道如何将消息发送到包含用户名的特定分区 i、 e: @MessageMapping(“/getNotifications”) @发送到(“/topic/notifications”) public@ResponseBody List getNotificationsWS(整数大小, SimpMessageHeaderAccessor headerAccessor,Principal Principal)引发异常{ 行动结果通知; notificat
@MessageMapping(“/getNotifications”)
@发送到(“/topic/notifications”)
public@ResponseBody List getNotificationsWS(整数大小,
SimpMessageHeaderAccessor headerAccessor,Principal Principal)引发异常{
行动结果通知;
notificationsAr=this.listNotifications(大小、主体);
返回notificationsAr.getResult();
}
我正在尝试将消息发送到“/topic/notifications/myUserName”而不是“/topic/notifications”。通过这种方式,每个登录的用户都从自己的分区进行消费
我怎么能做到 尝试注入
SimpMessagingTemplate
,然后您可以SimpMessagingTemplate.convertAndSendToUser(用户名,“/queue/reply”,消息)代码>
看看Thanh
@MessageMapping("/getNotifications")
@SendTo("/topic/notifications")
public @ResponseBody List<NotificationResponse> getNotificationsWS(int size,
SimpMessageHeaderAccessor headerAccessor, Principal principal) throws Exception {
ActionResult<List<NotificationResponse>> notificationsAr;
notificationsAr = this.listNotifications(size, principal);
return notificationsAr.getResult();
}