Socket Javascript does not connect (Stomp + Rabbitmq)

Asked

Viewed 125 times

3

I am trying to establish a communication between Rabbitmq and Javascript, to recover the log information that is sent to a Rabbitmq topic, but without success. In the console is displayed the following information:

Opening Web Socket...
WebSocket connection to 'ws://10.224.200.196:61613/' failed: WebSocket opening handshake timed out
Whoops! Lost connection to ws://10.224.200.196:61613/

This is my Javascript connection code:

   var test = {
            client: null,
            onConnect: function () {
                client.subscribe("add-on", this.onMessage, {ack: 'client'});
                console.log('connected');
            },
            onMessage: function (message) {
                console.log(message);
                message.ack();
            },
            onError: function () {
                console.log('error');
            },
            connect: function () {
                this.client = Stomp.client('ws://10.224.200.196:61613/', 'v11.stomp');
                this.client.connect('test', 'test', this.onConnect, this.onError, '/');
            }
        };
        test.connect();

User is created in Rabbitmq as "Monitoring"

inserir a descrição da imagem aqui

The Stomp plugin has been enabled

inserir a descrição da imagem aqui

I already created the topic through Rabbitmq

inserir a descrição da imagem aqui

I get these messages in the Rabbitmq log

=INFO REPORT==== 4-Oct-2017::08:05:07 ===
accepting STOMP connection <0.672.0> (10.224.200.188:56652 -> 10.224.200.196:61613)

=INFO REPORT==== 4-Oct-2017::08:09:07 ===
closing STOMP connection <0.672.0> (10.224.200.188:56652 -> 10.224.200.196:61613)

How do I connect and receive messages?

I’ve used several tutorials, the last were:

https://dzone.com/articles/easy-messaging-stomp-over

https://www.rabbitmq.com/stomp.html

1 answer

1


This problem happens because of the connection port that should be "15674".

Change the code:

this.client = Stomp.client('ws://10.224.200.196:61613/', 'v11.stomp');

For:

this.client = Stomp.client('ws://10.224.200.196:15674/ws', 'v11.stomp');

Below is an example of the changed code:

var test = {
        client: null,
        onConnect: function () {
            client.subscribe("/topic/add-on", this.onMessage, {ack: 'client'});
            console.log('connected');
        },
        onMessage: function (message) {
            console.log(message);
            message.ack();
        },
        onError: function () {
            console.log('error');
        },
        connect: function () {
            client = Stomp.client('ws://10.224.200.196:15674/ws', 'v11.stomp');
            client.connect('test', 'test', this.onConnect, this.onError, '/');
        }
    };
    test.connect();

Follow the documentation link

https://www.rabbitmq.com/web-stomp.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.