Check auth while sending a message to a specific user by using STOMP and WebSocket in Spring

前端 未结 2 725
梦毁少年i
梦毁少年i 2020-12-13 03:14

I\'m developing a realtime notification system in Spring 4 by using a build-in Message Broker, and STOMP over WebS

2条回答
  •  情书的邮戳
    2020-12-13 03:57

    Since users on my application are not authenticated I just used the session Id to differenciate the various topics

    on the server:

    template.convertAndSend("/topic/warnings/" + sessionId, ...)
    

    And the client is pretty straightforward

    stompClient.subscribe('/topic/warnings/${pageContext.session.id}', ...
    

    Maybe not the cleanest way but it works, and without authentication I couldn't make use of /user channel

提交回复
热议问题