我正在阅读书籍《Spring实战4》,以便使用WebSocket上的STOMP消息传递。
假设
然后,消息将会像这样发送到目的地:
假设
用户目标前缀设置为"/user"
如下:registry.setUserDestinationPrefix("/user");
然后客户端使用以下JavaScript代码订阅目标:
stomp.subscribe("/user/queue/notifications", handleNotifications);
然后在服务器上,客户端订阅的实际
目标应该从其会话中推导出来,可能是这样的:
/queue/notifications-user6hr83v6t --- (1)
然后我使用SimpMessagingTemplate
向该用户发送消息:
messaging.convertAndSendToUser( username, "/queue/notifications",
new Notification("You just got mentioned!"));
然后,消息将会像这样发送到目的地:
/user/<username>/queue/notifications ---(2)
好的,这两个目的地 (1)
和 (2)
看起来不同,那么信息怎么才能到达客户端呢?