Spring session + Spring web socket. Send message to specific client based on session id

前端 未结 2 960
臣服心动
臣服心动 2021-01-21 05:25

I have followed Quetion1 and Quetion2 from stack overflow to send messages to specific client, based on its sessionId but could not find success.

Below is my sample Rest

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 06:11

    If you are using /user channel as you do, try to pass the user as stated here.

    @MessageMapping("/messages")
    public void greeting(HelloMessage message, SimpMessageHeaderAccessor headerAccessor, Principal principal) 
        throws Exception {
        messagingTemplate.convertAndSendToUser(principal.getName(), "/queue/test", message);
    }
    

提交回复
热议问题