Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamic message-mapping for websockets in Spring 4

I want to develop a small chat with springs new websocket/stomp support. I guess i cannot use something like this:

@MessageMapping("/connect/{roomId}")
@SendTo("/topic/newMessage")
public String connectToChatRoom(@PathVariable String roomId, Principal p) {
    return getTimestamp() + " " + p.getName() + " connected to the room.";
}

What are my options for dynamic mapping here? As a client i want to subscribe only to the room I'm in.

Thanks in advance!

like image 528
kentobi Avatar asked Jan 17 '14 17:01

kentobi


1 Answers

Figured it out, you need to use @DestinationVariable instead of @PathVariable

like image 132
kentobi Avatar answered Sep 21 '22 12:09

kentobi