0
votes

I am working on a fun project which requires me to learn message queues and websockets. I am trying to connect browsers via websockets to an instance of rabbitmq using sockjs rather than pure websockets. On rabbit I have activated the plugins for stomp and web_stomp (web_stomp is required when using sockjs).

The problem I am running into is that while the call from the browser seems to be working properly because a very brief connection to Rabbit is made through the webstomp/stomp connection but after 2 or 3 seconds the connection is dropped by Rabbit.

This is confirmed by the rabbitmq logs:

=INFO REPORT==== 11-Jul-2016::23:01:54 === accepting STOMP connection (192.168.1.10:49746 -> 192.168.1.100:55674)
=INFO REPORT==== 11-Jul-2016::23:02:02 === closing STOMP connection (192.168.1.10:49746 -> 192.168.1.100:55674)

This is the browser code that connects to RabbitMQ via the webstomp plugin:

var url = "http://192.168.1.100:55674/stomp";
var ws = new SockJS(url);
var client = Stomp.over(ws);
var header = {
  login: 'test',
  passcode: 'test'
};
client.connect(header,
  function(){
    console.log('Hooray! Connected');
  },
  function(error){
    console.log('Error connecting to WS via stomp:' + JSON.stringify(error));
  }
);

Here is the Rabbit config:

[
    {rabbitmq_stomp, [{default_user, [{login, "test"},
                                    {passcode, "test"}
                                   ]
                    },
                    {tcp_listeners, [{"192.168.1.100", 55674}]},
                    {heartbeat, 0}
                   ]
    }
]

I have been over the Rabbit docs a million times but this feels like something simple that I am overlooking.

1

1 Answers

1
votes

Resolved. After combing through the logs I realized that web_stomp was listening on port 15674 so I changed the config file to reflect that. I swear I had made that change at some point but it did not seem to make a difference.

One of the late changes I made before sending out my request was to turn off heartbeat. Everything I have read states that sockjs does not support heartbeat and that there were suggestions to turn it off rather than use the default. In addition to turning off heartbeat in the config file I also added this to the browser code:

client.heartbeat.outgoing=0;
client.heartbeat.incoming=0;