1

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.