kentobi
kentobi

Reputation: 491

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!

Upvotes: 6

Views: 7083

Answers (2)

Rossen Stoyanchev
Rossen Stoyanchev

Reputation: 5008

Yes the @MessageMapping annotation (javaadoc) and the reference docs both list all supported arguments and return value types.

Upvotes: 0

kentobi
kentobi

Reputation: 491

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

Upvotes: 9

Related Questions