Commit b4058f37 by Chavee Issariyapat

add on_publish.js

parent 58b6cecc
{ {
"authserv_host" : "AUTH_SERVICE_HOST", "rabbitmq_host" : "RABBITMQ_HOST",
"authserv_port" : "AUTH_SERVICE_PORT" "rabbitmq_port" : "RABBITMQ_PORT",
"rabbitmq_username" : "RABBITMQ_USERNAME",
"rabbitmq_password" : "RABBITMQ_PASSWORD"
} }
...@@ -6,6 +6,15 @@ var LRU = require("lru-cache") , ...@@ -6,6 +6,15 @@ var LRU = require("lru-cache") ,
maxAge: 1000 * 60 * 5 maxAge: 1000 * 60 * 5
}); });
var client = require('seneca')()
.use('seneca-amqp-transport')
.client({
type: 'amqp',
pin: 'cmd:writefeed,feedid:serialno',
url: '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) {
...@@ -13,6 +22,28 @@ module.exports = function(options={}) { ...@@ -13,6 +22,28 @@ module.exports = function(options={}) {
if (options.debug) { if (options.debug) {
console.log('on_publish-------------'); console.log('on_publish-------------');
console.log(req.body); console.log(req.body);
var data = req.body;
if (data.topic.substring(0,5) == '$exec') {
var a = data.topic.split('/');
var p = data.payload.split(':');
switch (a[1]) {
case 'wf' :
case 'writefeed' :
var data = [{
"name": a[2],
"timestamp": Date.now(),
"data":data.payload,
"value": p[0],
"tags":{"attr":p[1]}
}];
break;
}
}
} }
var topic = req.body.topic; var topic = req.body.topic;
......
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