Spring 4中用于websocket的动态消息映射 [英] dynamic message-mapping for websockets in Spring 4

查看:145
本文介绍了Spring 4中用于websocket的动态消息映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在springs新的websocket/stomp支持下进行小型聊天. 我想我不能使用这样的东西:

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.

提前谢谢!

推荐答案

弄清楚了,您需要使用@DestinationVariable而不是@PathVariable

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

这篇关于Spring 4中用于websocket的动态消息映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆