Commit eb5c0866 by Chavee Issariyapat

update

parent 482eee0e
var config = require('config');
// https://github.com/isaacs/node-lru-cache
var LRU = require("lru-cache") ,
cache = LRU({
......@@ -13,6 +14,9 @@ var client = senecaAMQP.client({
url: 'amqp://'+config.get('rabbitmq_username')+':'+config.get('rabbitmq_password')+'@'+config.get('rabbitmq_host')+':'+config.get('rabbitmq_port')
});
//1----
console.log('amqp://'+config.get('rabbitmq_username')+':'+config.get('rabbitmq_password')+'@'+config.get('rabbitmq_host')+':'+config.get('rabbitmq_port'));
module.exports = function(options={}) {
return function(req, res, next) {
......@@ -21,7 +25,8 @@ module.exports = function(options={}) {
console.log('on_publish-------------');
console.log(req.body);
}
console.log(123);
console.log(data.topic.substring(0,5));
var data = req.body;
if (data.topic.substring(0,5) == '$exec') {
var stopic = data.topic.substr(6);
......@@ -32,24 +37,26 @@ module.exports = function(options={}) {
switch (a[0]) {
case 'wf' :
case 'writefeed' :
let wfmsg = [{
var wfmsg = [{
"topic": stopic,
"payload":ptext,
"ts": Date.now(),
"cid": data.client_id,
}];
console.log(1111);
console.log(wfmsg);
client.act('cmd:wf', {
message: JSON.stringify(wfmsg)
}, (err, res) => {
if (err) {
console.log(err);
throw err;
}
});
break;
case 'push' :
let pushmsg = [{
var pushmsg = [{
"topic": stopic,
"payload":ptext,
"ts": Date.now(),
......@@ -59,6 +66,7 @@ module.exports = function(options={}) {
message: JSON.stringify(pushmsg)
}, (err, res) => {
if (err) {
console.log(err);
throw err;
}
});
......@@ -68,9 +76,9 @@ module.exports = function(options={}) {
}
}
var topic = req.body.topic;
var cachekey = 'pub:'+req.body.client_id +':'+ req.body.username+':'+topic;
var authstatus = cache.get(cachekey);
// var topic = req.body.topic;
// var cachekey = 'pub:'+req.body.client_id +':'+ req.body.username+':'+topic;
// var authstatus = cache.get(cachekey);
res.status(200);
res.send('');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment