From c362cfa701a369be4726106fc8ac61a87712ea16 Mon Sep 17 00:00:00 2001 From: zeus Date: Sat, 27 Nov 2021 20:48:40 +0200 Subject: [PATCH] man poc --- .../ROOT/pages/doc-readmongo_service.adoc | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/poc-datacollector/modules/ROOT/pages/doc-readmongo_service.adoc b/poc-datacollector/modules/ROOT/pages/doc-readmongo_service.adoc index de69a33..a1625b2 100644 --- a/poc-datacollector/modules/ROOT/pages/doc-readmongo_service.adoc +++ b/poc-datacollector/modules/ROOT/pages/doc-readmongo_service.adoc @@ -5,6 +5,11 @@ src: readmongo/swarmlab-app/src/run/ + + + + + === stream2mongo [source,javascript] @@ -56,6 +61,51 @@ After clients insert new additional documents into a capped collection, the tail [source,javascript] ---- +const pubClient = new Redis({ + host: REDIS, + port: REDIS_PORT, +}); + +// read from redis +async function getkey(id) { + return new Promise((resolve) => { + pubClient.get(id, function (err, reply) { + if (err) { + resolve(null); + } else { + if (reply) { + //console.log("---------fount----------"); + resolve(1); + } else { + console.log("----------not fount------------"); + resolve(2); + } + } + }); + }); +} + +// check if stream exists +async function checkstream(data) { + var res = await getkey(data.id); + if (res == "1") { + console.log("Stream is on!"); + } else { + console.log("Creating Stream...."); + + var url = URL; + MongoClient.connect( + url, + { useNewUrlParser: true, useUnifiedTopology: true }, + function (err, db) { + if (err) throw err; + var dbo = db.db(DATABASE); + dbo.collection(COLLECTION, onCollectionNew.bind(data)); + } + ); + } +} + io.on("connection", (s) => { console.error("socket connection"); var usersession = new Object(); @@ -91,6 +141,10 @@ io.on("connection", (s) => { user: data, id: s.id, }; + checkstream(binddata); + }); + +} ----