Browse Source

man poc

master
zeus 3 years ago
parent
commit
c362cfa701
  1. 54
      poc-datacollector/modules/ROOT/pages/doc-readmongo_service.adoc

54
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);
});
}
----

Loading…
Cancel
Save