微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

保存 WebSocketSession 并通知该会话,

如何解决保存 WebSocketSession 并通知该会话,

我正在保存 webSocketSession,并在一种方法中检索该会话并向该会话发送消息,但在我的 websocket 客户端的 .html 文件中没有看到该消息,

@Override
public Mono<Void> handle(WebSocketSession webSocketSession) {
  
   sessions.put(webSocketSession.getId(),webSocketSession)
   return webSocketSession.send(Flux.interval(Duration.ofSeconds(20)).map(i -> 
      webSocketSession.textMessage("MessageSentDirectly")));
 }

public Mono<Void> sendNotification(String sessionId,String notificationMessage) {
    WebSocketSession session = sessions.get(sessionId);
   
    return session.send(Flux.interval(Duration.ofSeconds(1)).map(i -> 
     session.textMessage("MessageAfterRetreiveSession"))
    
 }

我有一个用于 WebsocketClient 的 .html 和 .js 文件,在该 html 文件中我可以看到 MessageSentDirectly 但我没有看到 MessageAfterRetreiveSession 字符串,

为什么我在调用 sendNotification 方法时没有在客户端收到 MessageAfterRetreiveSession?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。