Node.js+node_amqp.js can`t connect to ActiveMQ either 61616 or 5672 ports

1.8k Views Asked by At

need some advice.

This is example, which I start on node.js:

  var amqp = require('amqplib');

    amqp.connect('amqp://localhost:61616').then(function(conn) {
      conn.once('SIGINT', function() { conn.close(); });
      return conn.createChannel().then(function(ch) {
        var ok = ch.assertQueue('xxx', {durable: true});
        ok = ok.then(function() { ch.prefetch(1); });
        ok = ok.then(function() {
          ch.consume('xxx', doWork, {noAck: false});
          console.log(" [*] Waiting for messages. To exit press CTRL+C");
        });
        return ok;

        function doWork(msg) {
          var body = msg.content.toString();
          console.log(" [x] Received '%s'", body);
          var secs = body.split('.').length - 1;
          //console.log(" [x] Task takes %d seconds", secs);
          setTimeout(function() {
            console.log(" [x] Done");
            ch.ack(msg);
          }, secs * 1000);
        }
      });
    }).then(null, console.warn);

ActiveMQ write to log this:

WARN  | Transport Connection to: tcp://127.0.0.1:34186 failed: java.io.EOFException | org.apache.activemq.broker.TransportConnection.Transport | ActiveMQ Transport: tcp:///127.0.0.1:34186@61616
2013-08-19 09:54:52,391 | WARN  | Transport Connection to: tcp://192.168.2.129:56201 failed: java.io.EOFException | org.apache.activemq.broker.TransportConnection.Transport | ActiveMQ Transport: tcp:///192.168.2.129:56201@61616
2013-08-19 09:55:26,477 | WARN  | Transport Connection to: tcp://127.0.0.1:38096 failed: java.io.EOFException | org.apache.activemq.broker.TransportConnection.Transport | ActiveMQ Transport: tcp:///127.0.0.1:38096@61616

I think, this error because protocol for 61616 port is tcp, but not amqp. But when I try change port to 5672 in console output I see this:

Error: Unexpected close
    at new Connection (/home/nodejs/node_modules/amqplib/lib/connection.js:22:42)
    at Socket.onConnect (/home/nodejs/node_modules/amqplib/lib/api.js:92:13)
    at Socket.g (events.js:175:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at Object.afterConnect [as oncomplete] (net.js:883:10)

netstat -antp return this:

# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:53397           0.0.0.0:*               LISTEN      735/rpc.statd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2219/sshd
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      578/smbd
tcp        0      0 0.0.0.0:1024            0.0.0.0:*               LISTEN      1440/samba
tcp        0      0 127.0.0.1:7175          0.0.0.0:*               LISTEN      1488/postgres
tcp        0      0 0.0.0.0:135             0.0.0.0:*               LISTEN      1440/samba
tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      578/smbd
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      667/portmap
tcp        0     52 192.168.2.129:22        192.168.2.130:1780      ESTABLISHED 2892/4
tcp        0      0 192.168.2.129:445       192.168.2.130:1857      ESTABLISHED 5186/smbd
tcp6       0      0 :::22                   :::*                    LISTEN      2219/sshd
tcp6       0      0 :::11099                :::*                    LISTEN      3168/java
tcp6       0      0 :::8161                 :::*                    LISTEN      3168/java
tcp6       0      0 :::44066                :::*                    LISTEN      3168/java
tcp6       0      0 :::49831                :::*                    LISTEN      3168/java
tcp6       0      0 ::1:7175                :::*                    LISTEN      1488/postgres
tcp6       0      0 :::5672                 :::*                    LISTEN      3168/java
tcp6       0      0 :::1099                 :::*                    LISTEN      3168/java
tcp6       0      0 :::61616                :::*                    LISTEN      3168/java
tcp6       0      0 127.0.0.1:8080          :::*                    LISTEN      1373/jsvc

As you can see, ActiveMQ listen on 5672.. but, don`t connect. Why??? I try other node.js modules like a node-amqp.js, and nothing change. May be I miss something in connection_tunnig? (frameSize, etc) Pls, really need advice. Thank you.

1

There are 1 best solutions below

2
On

From what I can tell from a quick Google search the node_amqp.js is written for AMQP spec 0.9.1 while ActiveMQ implements AMQP v1.0 so you wouldn't be able to connect via that client. You'd need to use an AMQP v1.0 compliant client library to connect to ActiveMQ on the exposed AMQP transport port.