Dynamic queues are not created when subscribing to a Spring WebSocket topic with STOMP?

I am developing a push notification for all subsets of users who subscribe to a specific event. The user subscribes to a topic in RabbitMQ with the format: user-id.event-type.id. I use Spring Websocket, Stomp, RabbitMQ and frontend SockJS and Angular JS. The user should be notified of all actions (comments, etc.) about the event.

What we have so far:

First, I authenticate through the endpoint of the REST web service and put my token in the Cookie. Then we connect to the WebSocket. Users subscribe to the topic (/topic/user-45.meeting.1235) and they receive a notification. But my problem is that some users do not receive notifications. For the second user, for some reason, the queue is not created in RabbitMQ. Does anyone know why?

These are my broker settings in 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> 

and here's how to subscribe via 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 }); }); 

UPDATED

If we specify a unique Id field in the SUBSCRIBE frame, it creates a unique queue for each user. Is that the way?

+6
source share
1 answer

As I know, you need to subscribe to \queue not \topic . In this case, you do not need to configure the theme name for different users, which will be processed by sockjs depending on the registered user. And on the server, you can also send messages to a specific user using \queue\user\{username}\{name of queue}

+1
source

Source: https://habr.com/ru/post/980984/


All Articles