您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Spring Boot Websocket中向特定用户发送通知

在Spring Boot Websocket中向特定用户发送通知

gerrytan对在SpringWebsocket上向特定用户发送消的回答提到了Web套接字配置更改,以注册/user前缀。就您而言,我想这意味着要更换

registry.enableSimpleBroker("/topic", "/queue");

registry.enableSimpleBroker("/topic", "/queue", "/user");

他还说,在控制器中,您不需要/user前缀,因为它是自动添加的。因此,您可以尝试以下操作:

template.convertAndSendToUser(principal.getName(), "/queue/notification", notifications);

和这个:

template.convertAndSendToUser(principal.getName(), "/user/queue/notification", notifications);

在客户端,您需要提供用于连接服务器的用户名。您可以直接将其插入:

stompClient.subscribe('/user/naila/queue/notification', ...)

或从标题获取它。但是马库斯在“如何向特定用户发送网络套接字消息”中)说?即使在这里您也不需要用户名,因此它可能像这样工作:

stompClient.subscribe('/user/queue/notification', ...)
Java 2022/1/1 18:19:48 有466人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶