Search code examples
springwebsocketstompspring-websocketsockjs

How to read latest info from client side using Spring on backend?


Lately I was doing tutorial: https://spring.io/guides/gs/messaging-stomp-websocket/

And I want to do something similar.

1. Client pushed button on web application
2. I start doing some heavy operation on server
3. I want to inform client in text box how its going for example:
- Started calculating fields
- Calculated fields
- Starting rendering Etc.

How to achieve that realtime information is given to web application client while doing some operations?

Something like console output, but sended to end user.


Solution

  • You can inject SimpMessageSendingOperations into any of your services. You can use it to send arbitrary messages to destinations. You can use convertAndSendToUser if you have security configured, otherwise, you can use convertAndSend. Just make sure the client is subscribed to the destination you are sending messages to.