Node.js + node_amqp.js无法连接到ActiveMQ 61616或5672端口

时间:2013-08-19 14:07:08

标签: javascript node.js activemq node-amqp py-amqplib

需要一些建议。

这是我从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写入以记录此信息:

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

我认为,这个错误是因为61616端口的协议是tcp,而不是amqp。 但是当我尝试在控制台输出中将端口更改为5672时,我看到了:

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返回:

# 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

正如你所看到的,ActiveMQ在5672上听...但是,不要连接。为什么??? 我尝试其他node.js模块,如node-amqp.js,没有任何改变。 可能是我想念connection_tunnig中的一些东西? (frameSize等) 请,真的需要建议。谢谢。

1 个答案:

答案 0 :(得分:1)

从快速Google搜索中我可以看出,node_amqp.js是针对AMQP规范0.9.1编写的,而ActiveMQ是为了实现AMQP v1.0,因此您将无法通过该客户端进行连接。您需要使用符合AMQP v1.0的客户端库连接到公开的AMQP传输端口上的ActiveMQ。