Rabbitmq not connecting to websocket using nodejs app.

603 views
Skip to first unread message

akhiles...@paxcel.net

unread,
Sep 16, 2014, 5:00:17 AM9/16/14
to rabbitm...@googlegroups.com
Hi there,

I want to create a node js app(without html) which connects to rabbitmq broker at 61613(port of rabbitmq-stomp plugin) as client showing all the subscribed message on the console itself.

For that I am using Rabbitmq(obviously),Nodejs and stompjs module of nodejs(as mentioned on "https://github.com/jmesnil/stomp-websocket")

i.e.         npm install stompjs
var Stomp = require('stompjs');
var client = Stomp.overWS('ws://localhost:61613');
client.connect(un,pw,onconnect,onerror);

but it is not opening websocket.
What I think is that stompjs ultimately uses the websocket of browser but I am trying to implement that without browser,so this may be the issue.

Please help me to get over this problem.

Thanks in advance.

Michael Klishin

unread,
Sep 16, 2014, 5:04:04 AM9/16/14
to akhiles...@paxcel.net, rabbitm...@googlegroups.com
You're trying to use a WebSTOMP client, which is STOMP over WebSocket.
Port 61613 is for "vanilla" STOMP. Use a "regular" STOMP Node.js client.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ

akhiles...@paxcel.net

unread,
Sep 16, 2014, 6:12:20 AM9/16/14
to rabbitm...@googlegroups.com, akhiles...@paxcel.net
Thanks MK for quick reply.

Yes you are right I am using WebStomp because this is the plugin of rabbitmq which is used for the websockets, as regular Stomp is just enabling the stomp protocol in rabbitmq. Although I am using stompjs which is stomp for web browser and nodejs also.

I think that stompjs will suffice the requirement.

Correct me if I am wrong and please answer little more verbose.

Michael Klishin

unread,
Sep 16, 2014, 6:16:13 AM9/16/14
to akhiles...@paxcel.net, rabbitm...@googlegroups.com
On 16 September 2014 at 14:12:28, akhiles...@paxcel.net (akhiles...@paxcel.net) wrote:
>  Yes you are right I am using WebStomp because this is the plugin
> of rabbitmq which is used for the websockets, as regular Stomp
> is just enabling the stomp protocol in rabbitmq. Although I am
> using stompjs which is stomp for web browser and nodejs also.
>
> I think that stompjs will suffice the requirement.

If stompjs works on node with regular STOMP brokers, this code:

var Stomp = require('stompjs');
var client = Stomp.overWS('ws://localhost:61613');

connects to 61613 — the regular, non-WS STOMP port — over a WebSocket.

If you want to connect over a WebSocket, you need to use WebSTOMP, which
uses port 15674, as documented on
http://www.rabbitmq.com/web-stomp.html.

But I suspect what you really want is to use a regular STOMP-over-TCP connection
to port 61613.

akhiles...@paxcel.net

unread,
Sep 16, 2014, 6:19:33 AM9/16/14
to rabbitm...@googlegroups.com
Actually MK what I want is Stomp over websocket,yeah I admit the port am using is wrong.I'll correct that but still its not connecting to websocket.

Michael Klishin

unread,
Sep 16, 2014, 6:28:03 AM9/16/14
to akhiles...@paxcel.net, rabbitm...@googlegroups.com
 On 16 September 2014 at 14:19:41, akhiles...@paxcel.net (akhiles...@paxcel.net) wrote:
> I admit the port am using is wrong.I'll correct that but still
> its not connecting to websocket.

And what happens? "not connecting" is not very specific.

Have you enabled the web-stomp plugin and restarted RabbitMQ?

Akhilesh Saini

unread,
Sep 16, 2014, 6:34:24 AM9/16/14
to Michael Klishin, rabbitm...@googlegroups.com
Yes MK,web stomp is enabled and restarted rabbitmq and examples are also working fine...but in case of examples they are using extra sockjs library...which I can't use in my nodejs app.

In stomp-node.js file of stompjs,it is not able to call the "connect" to websocket. The bold red colored event.


wrapWS = function(url) {
    var WebSocketClient, connection, socket, ws;
    WebSocketClient = require('websocket').client;
    connection = null;
    ws = {
      url: url,
      send: function(d) {
        return connection.sendUTF(d);
      },
      close: function() {
        return connection.close();
      }
    };
    socket = new WebSocketClient();
    socket.on('connect', function(conn) {
      connection = conn;
      ws.onopen();
      connection.on('error', function(error) {
        return typeof ws.onclose === "function" ? ws.onclose(error) : void 0;
      });
      connection.on('close', function() {
        return typeof ws.onclose === "function" ? ws.onclose() : void 0;
      });
      return connection.on('message', function(message) {
        var event;
        if (message.type === 'utf8') {
          event = {
            'data': message.utf8Data
          };
          return ws.onmessage(event);
        }
      });
    });
    socket.connect(url);
    return ws;
  };
--
Regards
Akhilesh Saini
Software Engineer-Java
Paxcel Technologies
Mobile-07696338575

Michael Klishin

unread,
Sep 16, 2014, 6:47:47 AM9/16/14
to Akhilesh Saini, rabbitm...@googlegroups.com
On 16 September 2014 at 14:34:23, Akhilesh Saini (akhiles...@paxcel.net) wrote:
> Yes MK,web stomp is enabled and restarted rabbitmq and examples
> are also working fine...but in case of examples they are using
> extra sockjs library...which I can't use in my nodejs app.

WebSTOMP currently assumes SockJS, I believe. So your only option is to Node
with STOMP without WebSockets/WebSTOMP.

Akhilesh Saini

unread,
Sep 16, 2014, 7:02:44 AM9/16/14
to Michael Klishin, rabbitm...@googlegroups.com
Thanks a lot MK.

MK,don't we have any workaround using SockJS.If you come across kindly let me know(if possible).


Thanks.
Reply all
Reply to author
Forward
0 new messages