/**
|
* Created by bin.shen on 03/12/2016.
|
*/
|
|
var amqp = require('amqplib/callback_api');
|
var moment = require('moment');
|
|
var uri = 'amqp://guest:guest@121.40.92.176';
|
var ex = 'ex_data_dev1';
|
|
module.exports.publishMessage = function(data) {
|
amqp.connect(uri, function(err, conn) {
|
conn.createChannel(function(err, ch) {
|
ch.assertExchange(ex, 'fanout', { durable: false });
|
var message = '{"data": "' + data + '", "time":"' + moment().format('YYYY-MM-DD HH:mm:ss') + '"}';
|
ch.publish(ex, '', new Buffer(message));
|
});
|
setTimeout(function() {
|
conn.close();
|
//process.exit(0)
|
}, 500);
|
});
|
};
|
|
module.exports.pushToScreen = function(data) {
|
amqp.connect(uri, function(err, conn) {
|
conn.createChannel(function(err, ch) {
|
var _ex = 'ex_data_screen';
|
ch.assertExchange(_ex, 'fanout', { durable: false });
|
ch.publish(_ex, '', new Buffer(JSON.stringify(data)));
|
});
|
setTimeout(function() {
|
conn.close();
|
}, 500);
|
});
|
};
|