Commit e8b048cd by Chavee Issariyapat

fix seneca

parent 877a1dc1
{ {
"rabbitmq_host" : "npn1.kube.nexpie.com", "rabbitmq_host" : "npn1.kube.nexpie.com",
"rabbitmq_port" : "31672", "rabbitmq_port" : "32672",
"rabbitmq_username" : "b1ffb9e39865f3cb70cc2ef14920e023", "rabbitmq_username" : "b1ffb9e39865f3cb70cc2ef14920e023",
"rabbitmq_password" : "c3efbc0c4bdb1747a31cebac20d9b9b8" "rabbitmq_password" : "c3efbc0c4bdb1747a31cebac20d9b9b8"
} }
process.env["NODE_ENV"] = "development"; // process.env["NODE_ENV"] = "development";
process.env["NODE_CONFIG_DIR"] = __dirname + "/config/"; // process.env["NODE_CONFIG_DIR"] = __dirname + "/config/";
var restify = require('restify'); var restify = require('restify');
var on_publish = require('./on_publish')({debug:true}); var on_publish = require('./on_publish')({debug:true});
......
...@@ -6,7 +6,7 @@ var LRU = require("lru-cache") , ...@@ -6,7 +6,7 @@ var LRU = require("lru-cache") ,
maxAge: 1000 * 60 * 5 maxAge: 1000 * 60 * 5
}); });
var client = require('seneca')() var client_wf = require('seneca')()
.use('seneca-amqp-transport') .use('seneca-amqp-transport')
.client({ .client({
type: 'amqp', type: 'amqp',
...@@ -15,6 +15,16 @@ var client = require('seneca')() ...@@ -15,6 +15,16 @@ var client = require('seneca')()
}); });
var client_push = require('seneca')()
.use('seneca-amqp-transport')
.client({
type: 'amqp',
pin: 'cmd:push',
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) {
...@@ -31,19 +41,18 @@ module.exports = function(options={}) { ...@@ -31,19 +41,18 @@ module.exports = function(options={}) {
var ptext = Buffer.from(data.payload, 'base64').toString(); var ptext = Buffer.from(data.payload, 'base64').toString();
if (stopic && ptext) { if (stopic && ptext) {
let msg;
switch (a[0]) { switch (a[0]) {
case 'wf' : case 'wf' :
case 'writefeed' : case 'writefeed' :
msg = [{ let wfmsg = [{
"topic": stopic, "topic": stopic,
"payload":ptext, "payload":ptext,
"ts": Date.now(), "ts": Date.now(),
"cid": data.client_id, "cid": data.client_id,
}]; }];
client.act('cmd:wf', { client_wf.act('cmd:wf', {
message: JSON.stringify(msg) message: JSON.stringify(wfmsg)
}, (err, res) => { }, (err, res) => {
if (err) { if (err) {
throw err; throw err;
...@@ -52,14 +61,14 @@ module.exports = function(options={}) { ...@@ -52,14 +61,14 @@ module.exports = function(options={}) {
break; break;
case 'push' : case 'push' :
msg = [{ let pushmsg = [{
"topic": stopic, "topic": stopic,
"payload":ptext, "payload":ptext,
"ts": Date.now(), "ts": Date.now(),
"cid": data.client_id, "cid": data.client_id,
}]; }];
client.act('cmd:push', { client_push.act('cmd:push', {
message: JSON.stringify(msg) message: JSON.stringify(pushmsg)
}, (err, res) => { }, (err, res) => {
if (err) { if (err) {
throw err; throw err;
......
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