Skip to content

Instantly share code, notes, and snippets.

@syndr0m
Last active December 21, 2015 08:51
Show Gist options
  • Save syndr0m/a586e50e7581a7d9b947 to your computer and use it in GitHub Desktop.
Save syndr0m/a586e50e7581a7d9b947 to your computer and use it in GitHub Desktop.
'use strict';
var amqp = require('amqplib/callback_api');
var connect = function () {
amqp.connect('amqp://rabbitmq-1.adm.afrostream.net', function (err, conn) {
if (err) {
console.error('test mq: cannot connect to mq ', err);
} else {
console.log('test mq: connected to mq');
conn.on('error', function (e) {
console.error('test mq: disconnected from mq', e);
connect.ch = null;
});
conn.createChannel(function (err, ch) {
// exporting channel.
connect.ch = ch;
});
}
});
};
var send = function (data) {
try {
if (connect.ch) {
var exchangeName = 'afrostream-api-stats';
connect.ch.assertExchange(exchangeName, 'fanout', {durable: true});
connect.ch.publish(exchangeName, '', new Buffer(JSON.stringify(data)));
console.log('DONE');
}
} catch (e) {
console.error('test mq: Exception fwd to mq : ', e);
}
};
connect();
setTimeout(function () {
send({type:'ping',user_id:42, ip:'8.8.8.8', fqdn:'hw.cdn.afrostream.net'});
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment