I'm tring rabbitmq-tutorials, ruby version works fine, but node.js version cannot send message. I do not know what is wrong.
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);
});
after I run node send.js
, runing process node recv.js
cannot recv anything. and rabbitmqctl list_queues
does not show hello_node
queues.
You need to indicate the queue then publish. That version should works:
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);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With