使用STOMP订阅主题Spring WebSocket时未创建动态队列?

Abz*_*tov 6 spring stomp rabbitmq sockjs spring-websocket

我正在为订阅特定事件的所有用户子集开发推送通知.用户使用以下格式订阅RabbitMQ中的主题:user-id.event-type.id.我使用Spring Websocket,Stomp,RabbitMQ和前端SockJS和Angular JS.应通知用户有关事件的所有操作(注释等,日期更改).

到目前为止我们有什么:

首先,我通过REST webservice端点进行身份验证,并将我的令牌放到Cookie中.然后我们连接到websocket.用户订阅主题(/topic/user-45.meeting.1235)并获得通知.但我的问题是有些用户没有收到通知.对于第二个用户,由于某种原因,未在RabbitMQ中创建队列.谁知道为什么?

这是我在Spring applicationContext.xml中的代理设置:

<websocket:message-broker application-destination-prefix="/app">
        <websocket:stomp-endpoint path="/stomp">
            <websocket:sockjs/>
        </websocket:stomp-endpoint>
        <websocket:stomp-broker-relay relay-host="localhost" relay-port="61613" system-login="guest" system-passcode="guest" prefix="/queue, /topic"/>
    </websocket:message-broker>
Run Code Online (Sandbox Code Playgroud)

这是通过Sockjs订阅的方式:

var ws = new SockJS('http://' + location.host + path);
var stompClient = Stomp.over(ws);
stompClient.connect({
    username: '',
    password: '',
    host: '/'
}, function () {
    stompClient.subscribe('/topic/user-45.meeting.' + obj.id,
        function (message) {
            console.log(message);
        }, {
            persistent: true
        });
});
Run Code Online (Sandbox Code Playgroud)

更新

如果我们在SUBSCRIBE帧中指定唯一的Id字段,它会为每个用户创建唯一的队列.是这样的吗?

Mas*_*ode 1

据我所知,你需要订阅\queuenot \topic。通过这样做,你不需要为不同的用户自定义主题名称,这将由 sockjs 根据登录的用户进行处理。并且在服务器端,你还可以向特定用户发送消息通过使用\queue\user\{username}\{name of queue}