From cd83ef88f783205bc17d06b249fa62f9425957c6 Mon Sep 17 00:00:00 2001
From: 沈斌 <bluelazysb@hotmail.com>
Date: Fri, 11 Aug 2017 09:54:33 +0800
Subject: [PATCH] 测试-不要频繁增加连接数

---
 queue.js |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/queue.js b/queue.js
index 841d19c..3642351 100644
--- a/queue.js
+++ b/queue.js
@@ -1,7 +1,6 @@
 /**
  * Created by bin.shen on 03/12/2016.
  */
-
 var amqp = require('amqplib/callback_api');
 var moment = require('moment');
 
@@ -11,7 +10,7 @@
     this.pushToMQ('ex_data_dev1', {
         data: data,
         time: moment().format('YYYY-MM-DD HH:mm:ss')
-    })
+    });
 };
 
 module.exports.pushToMQ = function(ex, data) {
@@ -24,4 +23,19 @@
             conn.close();
         }, 500);
     });
+};
+
+module.exports.listenToMQ = function(ex) {
+    amqp.connect(uri, function(err, conn) {
+        conn.createChannel(function(err, ch) {
+            ch.assertExchange(ex, 'fanout', { durable: false });
+            ch.assertQueue('', {exclusive: true}, function(err, q) {
+                ch.bindQueue(q.queue, ex, '');
+                ch.consume(q.queue, function(msg) {
+                    var message = JSON.parse(msg.content);
+                    global.configs[message.mac] = message;
+                }, { noAck: true });
+            });
+        });
+    });
 };
\ No newline at end of file

--
Gitblit v1.8.0