dynamic message-mapping for websockets in Spring 4

て烟熏妆下的殇ゞ 提交于 2019-12-20 16:52:32

问题


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!


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/21192091/dynamic-message-mapping-for-websockets-in-spring-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!