1

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.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
programmer
  • 101
  • 1
  • 9
  • I think client should subscribe websocket server by username or hash-username that already stored in database and then server can find username from database for send sms to particular user as you want. – Panup Pong Jun 07 '18 at 08:21

1 Answers1

0

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.

Oreste Viron
  • 3,592
  • 3
  • 22
  • 34
  • stompClient.subscribe('/topic/connect/'+theUserId, function (data) { //Handle data } }); here if a user subscribe with some other user name other's sms will go to the user. how to make a secutity check – programmer Jun 09 '18 at 21:47
  • 1
    can i make a authentication on subscription – programmer Jun 09 '18 at 21:49
  • Yes, you must prevent users to suscribe on another user's channel. It's possible but I don't remember how. – Oreste Viron Jun 10 '18 at 14:37