UNPKG

domotz-remote-pawn

Version:

Domotz Agent

22 lines (17 loc) 679 B
#!/usr/bin/env node var amqp = require('amqplib'); var when = require('when'); var args = process.argv.slice(2); var severity = (args.length > 0) ? args[0] : 'info'; var message = args.slice(1).join(' ') || 'Hello World!'; amqp.connect('amqp://localhost').then(function(conn) { return when(conn.createChannel().then(function(ch) { var ex = 'direct_logs'; var ok = ch.assertExchange(ex, 'direct', {durable: false}); return ok.then(function() { ch.publish(ex, severity, new Buffer(message)); console.log(" [x] Sent %s:'%s'", severity, message); return ch.close(); }); })).ensure(function() { conn.close(); }); }).then(null, console.warn);