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

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