node-amqp不能发送消息给RabbitMQ

我正在使用rabbitmq-tutorials ,ruby版本正常,但是node.js版本不能发送消息。 我不知道什么是错的。

var amqp = require('amqp'); var amqp_hacks = require('./amqp-hacks'); var connection = amqp.createConnection({host: 'localhost'}); connection.on('ready', function(){ connection.publish('hello_node', 'Hello World!'); console.log(" [x] Sent 'Hello World!'"); amqp_hacks.safeEndConnection(connection); }); 

在运行node send.js ,运行进程node recv.js不能node recv.js任何东西。 而rabbitmqctl list_queues不显示hello_node队列。

你需要指出队列然后发布。 该版本应该工作:

  var amqp = require('amqp'); var amqp_hacks = require('./amqp-hacks'); var connection = amqp.createConnection({host: 'localhost'}); connection.on('ready', function(){ connection.queue('hello_node', {'durable': false}, function(q){ connection.publish('hello_node', 'Hello World!'); console.log(" [x] Sent 'Hello World!' to 'hello_node'"); amqp_hacks.safeEndConnection(connection); }); });