Spring WebSocket @SendToSession: send message to specific session

No need to create specific destinations, it’s already done out of the box as of Spring 4.1 (see SPR-11309). Given users subscribe to a /user/queue/something queue, you can send a message to a single session with: As stated in the SimpMessageSendingOperations Javadoc, since your user name is actually a sessionId, you MUST set that as … Read more

Where “user” comes from in convertAndSendToUser works in SockJS+Spring Websocket?

We know we can send messages to the client from a stomp server using the topic prefixes that he is subscribed to e.g. /topic/hello. We also know we can send messages to a specific user because spring provides the convertAndSendToUser(username, destination, message) API. It accepts a String username which means if we somehow have a … Read more

Does Spring @SubscribeMapping really subscribe the client to some topic?

By default the return value from an @SubscribeMapping method is sent as a message directly back to the connected client and does not pass through the broker. (emphasis mine) Here the Spring Framework documentation is describing what happens with the response message, not the incoming SUBSCRIBE message. So to answer your questions: yes, the client … Read more

Path variables in Spring WebSockets @SendTo mapping

Even though @MessageMapping supports placeholders, they are not exposed / resolved in @SendTo destinations. Currently, there’s no way to define dynamic destinations with the @SendTo annotation (see issue SPR-12170). You could use the SimpMessagingTemplate for the time being (that’s how it works internally anyway). Here’s how you would do it: @MessageMapping(“/fleet/{fleetId}/driver/{driverId}”) public void simple(@DestinationVariable String … Read more