Commit 449bba05 authored by Kamron Aroonrua's avatar Kamron Aroonrua 💬

db

parent 5c14564c
...@@ -27,7 +27,7 @@ function RPCCaller(config) ...@@ -27,7 +27,7 @@ function RPCCaller(config)
ch.responseEmitter = new EventEmitter(); ch.responseEmitter = new EventEmitter();
ch.responseEmitter.setMaxListeners(0); ch.responseEmitter.setMaxListeners(0);
ch.consume(REPLY_QUEUE , ch.consume(REPLY_QUEUE ,
(msg) => channel.responseEmitter.emit(msg.properties.correlationId, JSON.parse(msg.content.toString())), (msg) => { console.log('reply consumee'); ch.responseEmitter.emit(msg.properties.correlationId, JSON.parse(msg.content.toString()))},
{noAck: true}); {noAck: true});
self.opened = true; self.opened = true;
...@@ -43,15 +43,14 @@ function RPCCaller(config) ...@@ -43,15 +43,14 @@ function RPCCaller(config)
RPCCaller.prototype.call = function(req,cb){ RPCCaller.prototype.call = function(req,cb){
var self = this; var self = this;
var corr = generateUuid(); var corr = generateUuid();
console.log('callllll') self.open(function(err){
this.open(function(err){
if(err){ if(err){
console.log(err); console.log(err);
} }
self.ch.responseEmitter.once(corr, (resp)=>{ self.ch.responseEmitter.once(corr, (resp)=>{
cb(null,resp); cb(null,resp);
}); });
self.ch.sendToQueue(self.name, new Buffer(JSON.stringify(req)), { correlationId: corr, replyTo: REPLY_QUEUE }) self.ch.sendToQueue(self.name, new Buffer(JSON.stringify(req)), { corr, replyTo: REPLY_QUEUE })
}); });
function generateUuid() { function generateUuid() {
......
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