Spring Websockets @SendToUser without login?

后端 未结 4 1770
梦毁少年i
梦毁少年i 2020-12-09 04:52

I have a simple spring application with websocket functionality and everything works so far. Now I want to send a message from my server to a specific client using the @Send

4条回答
  •  半阙折子戏
    2020-12-09 05:17

    Try this. It worked for me

    @Autowired
    private SimpMessagingTemplate messagingTemplate;
    
    @MessageMapping("/getHello")
    public void sendReply( MessageHeaders messageHeaders, @Payload String message, @Header(name = "simpSessionId") String sessionId){
            messagingTemplate.convertAndSendToUser(sessionId, "/queue/hello", "Hello "+ message, messageHeaders);
    }
    

提交回复
热议问题