需要一些建议。
这是一个示例,我从 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 等)请,真的需要建议。谢谢你。