From ddfcebeefdb5253244f82bd3794a711ee32bdd2b Mon Sep 17 00:00:00 2001
From: 沈斌 <bluelazysb@hotmail.com>
Date: Sun, 25 Dec 2016 00:19:42 +0800
Subject: [PATCH] 删除冗余的代码,提升性能
---
queue.js | 39 ++++++++-------------------------------
1 files changed, 8 insertions(+), 31 deletions(-)
diff --git a/queue.js b/queue.js
index 791837d..6ee7599 100644
--- a/queue.js
+++ b/queue.js
@@ -9,40 +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) {
- ch.assertExchange('ex_data_screen', 'fanout', { durable: false });
- var message = {
- mac: data.mac,
- address: "���������������������������������",
- location: {
- lat:31.430616,
- lng:120.988327
- },
- data: {
- x1: data.x1,
- x2: data.x2,
- x3: data.x3,
- x4: data.x4,
- x5: data.x5,
- x6: data.x6
- }
- };
- ch.publish('ex_data_screen', '', new Buffer(message));
+ ch.publish(ex, '', new Buffer(JSON.stringify(data)));
});
setTimeout(function() {
conn.close();
--
Gitblit v1.8.0