I have implemented the following websocket endpoint
@MessageMapping("/socket/{myId}/")
@SendTo("/queue/myqueue")
public MyObject getObject(@DestinationVariable String myId) throws Exception {
return new MyObject("MyId:" + myId);
}
Now how can I send message to that endpoint from one of my service.java class? There will be front-end client as well, which will read the message from websocket once the service.java class's method send some message to websocket endpoint. I am a little confused that how can I do that?
Any help would be appreciated
When using a raw websocket(without STOMP), the message sent lacks of information to make Spring route it to a specific message handler method (we don't have any messaging protocol), so instead of annotating your controller, you'll have to implement a WebSocketHandler by extending TextWebSocketHandler public void handleTextMessage(WebSocketSession session, TextMessage message){ }
Checkout an example here spring boot websocket without STOMP and SockJs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With