_listenForResponses() { return this.channel.consume(this.replyQueue, msg => { const correlationId = msg.properties.correlationId; const handler = this.idToCallbackMap[correlationId]; if (handler) { handler(JSON.parse(msg.content.toString())); } }, {noAck: true}); }
handleRequest(handler) { return this.channel.consume(this.queue, msg => { const content = JSON.parse(msg.content.toString()); handler(content, reply => { this.channel.sendToQueue( msg.properties.replyTo, new Buffer(JSON.stringify(reply)), {correlationId: msg.properties.correlationId} ); this.channel.ack(msg); }); }); }