0
需要一些建議。Node.js + node_amqp.js無法連接到ActiveMQ 61616或5672端口
這就是例子,這是我開始的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:[email protected]
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:[email protected]
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:[email protected]
我認爲,這個錯誤是因爲協議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等) 請真的需要建議。謝謝。
不,你知道一些有用的東西嗎?我的意思是什麼庫可以符合ActiveMQ 5.8.0? – user2388748
https://github.com/joyent/node/wiki/modules#wiki-message-queue – user2388748
正如答案所述,任何符合AMQP v1.0的庫。 –