-
-
Save syndr0m/a586e50e7581a7d9b947 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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