Reputation: 203
I want to connect to my active message queue in node js this code is connecting to the queue, but the question is how to subscribe to a particular queue?
let ws = new WebSocket('ws://localhost:61614', 'stomp')
ws.onopen = () => {
console.log('opening...')
ws.send('CONNECT\n\n\0')
}
ws.onclose = () => console.log('closing...')
ws.onmessage = (e) => {
if (e.data.startsWith('MESSAGE')) {
console.log(e.data)
}
}
any suggeestion can be helpful, thanks
Upvotes: 1
Views: 633
Reputation: 203
I have figured the problem out the problem was in this line startsWith('MESSAGE')) it should be startsWith(''))
Upvotes: 1
Reputation: 6346
According to the Developer Mozilla documentation there is no 'particular' queue. See how to connect:
// Create WebSocket connection.
const socket = new WebSocket('ws://localhost:8080');
// Connection opened
socket.addEventListener('open', function (event) {
socket.send('Hello Server!');
});
// Listen for messages
socket.addEventListener('message', function (event) {
console.log('Message from server ', event.data);
});
Upvotes: 0