沈斌
2016-12-25 3d4d654cb24bc2293d964e8f1bc52418c089c6ee
queue.js
@@ -9,38 +9,17 @@
var ex = 'ex_data_dev1';
module.exports.publishMessage = function(data) {
    this.pushToMQ({
        data: data,
        time: moment().format('YYYY-MM-DD HH:mm:ss')
    })
};
module.exports.pushToMQ = function(ex, 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);
    });
};
module.exports.pushToAlarm = function(data) {
    amqp.connect(uri, function(err, conn) {
        conn.createChannel(function(err, ch) {
            var _ex = 'ex_data_alarm';
            ch.assertExchange(_ex, 'fanout', { durable: false });
            ch.publish(_ex, '', new Buffer(JSON.stringify(data)));
            ch.publish(ex, '', new Buffer(JSON.stringify(data)));
        });
        setTimeout(function() {
            conn.close();