0

I have a messaging app and I am using stomp-websocket with spring.

I am sending message to sockets like:

messageBean.convertAndSend( "/topic/message.${USER_ID}",  ${Message_Object} )

However, for some cases I want to send message to whole users that actively have socket.

I mean, I want to send message like:

messageBean.convertAndSend( "/topic/message",  ${Message_Object} )

I mean I don't want to create new socket for this messages. The front end application which is using this socket like sockJs.subscribe("/topic/message.${userId}") I dont want to broke that logic.

How can I send the message like I said, or how can I achive this logic?

Thanks for helps.

gokhanbirincii
  • 575
  • 5
  • 15
  • You can get all the user active sessions iterate and send the message right ? – Robert Ellis May 06 '19 at 07:03
  • Yeah, I did the solution like that but little different, I wrote a listener class and listened all subscription events of sockets that i want to listen and then i stored that list. – gokhanbirincii May 06 '19 at 18:11

1 Answers1

0

I'm not sure really sure if this answers your question, but methods that are annotated with @SendTo and @MessageMapping will automatically broadcast return value to all subscribers.

In case it might help you, here is an implementation of a Kalah game I wrote which uses Spring WebSocket to broadcast game status to active players in real time.

Seifeddine
  • 31
  • 1
  • 4
  • oh okey firstly thank you for your answer, I reviewed your codes that you have mentioned but I have actually websockets for every user like : `/topic/message.${userId}` and I need something like getting all sockets then parsing them and getting userIds, aftwerwards. – gokhanbirincii May 01 '19 at 11:50