I am developing push notification to all subset of users who subscribed to particular event. User subscribes to topic in RabbitMQ with format: user-id.event-type.id. I use Spring Websocket, Stomp, RabbitMQ and on frontend SockJS and Angular JS. User should be notified of all actions (comments etc, date change) about event.
What we have so far:
First I authenticate through REST webservice endpoint, and put my token to Cookie. Then we connect to websocket. Users subscribes to topic (/topic/user-45.meeting.1235) and they get notification. But my problem is some users do not receive notification. For second user, for some reason queue is not created in RabbitMQ. Anyone knows why?
This is 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 this is how subscribe through 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
});
});
If we specify unique Id field in SUBSCRIBE frame, it creates unique queue for each user. Is this way to go?
As per my knowledge you need to subscribe the \queue
not \topic
.By doing this you don't need to customize topic name for different users,that will be handled by sockjs depending on logged user.And at server side you can also send messages to particular user by using \queue\user\{username}\{name of queue}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With