Commit b8c89812 by Chavee Issariyapat

change msg format

parent de63d9cf
...@@ -10,7 +10,7 @@ var client = require('seneca')() ...@@ -10,7 +10,7 @@ var client = require('seneca')()
.use('seneca-amqp-transport') .use('seneca-amqp-transport')
.client({ .client({
type: 'amqp', type: 'amqp',
pin: 'cmd:writefeed,feedid:serialno', pin: 'cmd:wf',
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')
}); });
...@@ -26,27 +26,24 @@ module.exports = function(options={}) { ...@@ -26,27 +26,24 @@ module.exports = function(options={}) {
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 a = data.topic.split('/'); var a = data.topic.split('/');
var ptext = Buffer.from(data.payload, 'base64').toString(); var ptext = Buffer.from(data.payload, 'base64').toString();
// temp if (stopic && ptext) {
var p = ptext.split(':'); switch (a[0]) {
switch (a[1]) {
case 'wf' : case 'wf' :
case 'writefeed' : case 'writefeed' :
var data = [{
"name": a[2],
"timestamp": Date.now(),
"topic": data.topic,
"payload":ptext,
"value": p[1], // temp var msg = [{
"tags":{"attr":p[0]} // temp "topic": stopic,
"payload":ptext,
"ts": Date.now(),
"cid": data.client_id,
}]; }];
client.act('cmd:writefeed,feedid:serialno', { client.act('cmd:wf', {
message: JSON.stringify(data) message: JSON.stringify(msg)
}, (err, res) => { }, (err, res) => {
if (err) { if (err) {
throw err; throw err;
...@@ -56,6 +53,7 @@ module.exports = function(options={}) { ...@@ -56,6 +53,7 @@ module.exports = function(options={}) {
break; break;
} }
} }
}
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;
......
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