domotz-remote-pawn
Version:
Domotz Agent
25 lines (20 loc) • 820 B
JavaScript
var amqp = require('amqplib');
var when = require('when');
amqp.connect('amqp://localhost').then(function(conn) {
return when(conn.createChannel().then(function(ch) {
var q = 'hello';
var msg = 'Hello World!';
var ok = ch.assertQueue(q, {durable: false});
return ok.then(function(_qok) {
// NB: `sentToQueue` and `publish` both return a boolean
// indicating whether it's OK to send again straight away, or
// (when `false`) that you should wait for the event `'drain'`
// to fire before writing again. We're just doing the one write,
// so we'll ignore it.
ch.sendToQueue(q, new Buffer(msg));
console.log(" [x] Sent '%s'", msg);
return ch.close();
});
})).ensure(function() { conn.close(); });
}).then(null, console.warn);