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

前端 未结 2 959
臣服心动
臣服心动 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:03

    I've found a full workable Spring Stomp Chat project in git, the link is here. You can refer to it. https://gist.github.com/theotherian/9906304

    0 讨论(0)
  • 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);
    }
    
    0 讨论(0)
提交回复
热议问题