Search code examples
springspring-bootstompspring-websocketmessagebroker

how to send message to a specific user by username at any application point


I am implementing spring boot stomp message broker socket to interact with webclient. i need to send sms to a specific user by username at some application point,means the message will be trigger from server to client. client will subscribe to a topic/queue. i heard @SendtoUser send sms to the perticular user, but here in my case user is just subscribing a topic, then from backend i need to send sms time to time to specific user. user will not send any sms to server. its just push based sms.

messagingTemplate.convertAndSendToUser(sessionId,"/queue/something", payload, 
    headerAccessor.getMessageHeaders());

but here from where will i get the session id for the targeted user. here user is just subscribing the topic once.


Solution

  • You can find answer to a similar question (with project exemple) here : Spring websocket send to specific people

    The fact that user is subscribing once is not a problem. One the connection is established, the server can send has much message as needed.