Commit eb5c0866 by Chavee Issariyapat

update

parent 482eee0e
var config = require('config'); var config = require('config');
// https://github.com/isaacs/node-lru-cache // https://github.com/isaacs/node-lru-cache
var LRU = require("lru-cache") , var LRU = require("lru-cache") ,
cache = LRU({ cache = LRU({
...@@ -13,6 +14,9 @@ var client = senecaAMQP.client({ ...@@ -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') 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={}) { module.exports = function(options={}) {
return function(req, res, next) { return function(req, res, next) {
...@@ -21,7 +25,8 @@ module.exports = function(options={}) { ...@@ -21,7 +25,8 @@ module.exports = function(options={}) {
console.log('on_publish-------------'); console.log('on_publish-------------');
console.log(req.body); console.log(req.body);
} }
console.log(123);
console.log(data.topic.substring(0,5));
var data = req.body; var data = req.body;
if (data.topic.substring(0,5) == '$exec') { if (data.topic.substring(0,5) == '$exec') {
var stopic = data.topic.substr(6); var stopic = data.topic.substr(6);
...@@ -32,24 +37,26 @@ module.exports = function(options={}) { ...@@ -32,24 +37,26 @@ module.exports = function(options={}) {
switch (a[0]) { switch (a[0]) {
case 'wf' : case 'wf' :
case 'writefeed' : case 'writefeed' :
let wfmsg = [{ var wfmsg = [{
"topic": stopic, "topic": stopic,
"payload":ptext, "payload":ptext,
"ts": Date.now(), "ts": Date.now(),
"cid": data.client_id, "cid": data.client_id,
}]; }];
console.log(1111);
console.log(wfmsg);
client.act('cmd:wf', { client.act('cmd:wf', {
message: JSON.stringify(wfmsg) message: JSON.stringify(wfmsg)
}, (err, res) => { }, (err, res) => {
if (err) { if (err) {
console.log(err);
throw err; throw err;
} }
}); });
break; break;
case 'push' : case 'push' :
let pushmsg = [{ var pushmsg = [{
"topic": stopic, "topic": stopic,
"payload":ptext, "payload":ptext,
"ts": Date.now(), "ts": Date.now(),
...@@ -59,6 +66,7 @@ module.exports = function(options={}) { ...@@ -59,6 +66,7 @@ module.exports = function(options={}) {
message: JSON.stringify(pushmsg) message: JSON.stringify(pushmsg)
}, (err, res) => { }, (err, res) => {
if (err) { if (err) {
console.log(err);
throw err; throw err;
} }
}); });
...@@ -68,9 +76,9 @@ module.exports = function(options={}) { ...@@ -68,9 +76,9 @@ module.exports = function(options={}) {
} }
} }
var topic = req.body.topic; // var topic = req.body.topic;
var cachekey = 'pub:'+req.body.client_id +':'+ req.body.username+':'+topic; // var cachekey = 'pub:'+req.body.client_id +':'+ req.body.username+':'+topic;
var authstatus = cache.get(cachekey); // var authstatus = cache.get(cachekey);
res.status(200); res.status(200);
res.send(''); 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