简体   繁体   中英

read message from message queue in node.js

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

I have figured the problem out the problem was in this line startsWith('MESSAGE')) it should be startsWith(''))

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);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM