【问题标题】:Node.js+node_amqp.js can`t connect to ActiveMQ either 61616 or 5672 portsNode.js+node_amqp.js 无法连接到 ActiveMQ 61616 或 5672 端口
【发布时间】:2013-08-21 08:55:09
【问题描述】:

需要一些建议。

这是一个例子,我从 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 中的某些内容吗? (帧大小等) 请,真的需要建议。谢谢。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 不,你知道一些有用的东西吗??我的意思是什么库可以与 ActiveMQ 5.8.0 兼容?
    • 正如答案所说,任何符合 AMQP v1.0 的库。
    猜你喜欢
    • 1970-01-01
    • 2017-10-07
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 2019-07-31
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多