Commit f0d98038 authored by project's avatar project

--no commit message

--no commit message
parent a05984c2
var amqp = require('amqplib/callback_api');
var thunky = require('thunky');
function EventPub(config)
{
this.config = config;
this.url = config.url;
this.name = config.name || "event_group";
this.conn = null;
this.ch = null;
var self = this;
this.opened = false;
this.open = thunky(open);
this.open();
function open (cb) {
//console.log('connecting');
amqp.connect(self.url, function(err, conn) {
if (err){return cb(err)}
conn.createChannel(function(err, ch) {
if (err){return cb(err)}
var ex = self.name;
ch.assertExchange(ex, 'topic', {durable: false});
self.opened = true;
self.conn = conn;
self.ch = ch;
cb();
});
});
}
}
EventPub.prototype.send = function(topic,msg,cb)
{
var self=this;
this.open(function(err){
self.ch.publish(self.name, topic, new Buffer(msg));
});
}
module.exports = EventPub;
......@@ -29,6 +29,7 @@
"query-string": "^4.2.3",
"quickq": "^0.8.1",
"random-access-file": "^1.3.0",
"request": "^2.79.0"
"request": "^2.79.0",
"thunky": "^1.0.2"
}
}
......@@ -78,17 +78,24 @@ const crypto = require("crypto");
// atext = JSON.stringify(a);
// redis.set('a',atext)
var HttpACL = ctx.getLib('lib/mems/http-acl');
// var HttpACL = ctx.getLib('lib/mems/http-acl');
//
// var httpacl = HttpACL.create({'conn':'redis://:@lab1.igridproject.info:6379/1'});
//
// httpacl.add({'appkey':'app1','method':'get','jobid':'job1'})
// httpacl.add({'appkey':'app2','method':'get','jobid':'job2'})
// httpacl.add({'appkey':'app1','method':'get','jobid':'job3'})
// httpacl.commit();
//
// httpacl.update(function(err){
// //console.log(httpacl.acl);
// var j = httpacl.findJob('app1','get');
// console.log(j);
// });
var httpacl = HttpACL.create({'conn':'redis://:@lab1.igridproject.info:6379/1'});
var EvenPub = ctx.getLib('lib/amqp/event-pub');
httpacl.add({'appkey':'app1','method':'get','jobid':'job1'})
httpacl.add({'appkey':'app2','method':'get','jobid':'job2'})
httpacl.add({'appkey':'app1','method':'get','jobid':'job3'})
httpacl.commit();
var evp = new EvenPub({'url':'amqp://lab1.igridproject.info','name':'topic_logs'});
httpacl.update(function(err){
//console.log(httpacl.acl);
var j = httpacl.findJob('app1','get');
console.log(j);
});
evp.send('q.test.t1','kamron aroonrua');
evp.send('q.test.t1','kamron aroonrua aaa');
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