this is how i consume the queue in rabbit, i wonder why this promise still hangs and return no result. i am trying to hit an endpoint that call this promise and expect it to return just ok to make sure it gives me a 200 OK status. now it acts like it somehow does not get any return from this service, i wonder what i did wrong. thanks
return new Promise((resolve,reject) => {
try{
rabbit.then(conn => {
return conn.createChannel();
})
.then(ch => {
let shit = ch.assertQueue(USER_LOG_QUEUE)
.then(ok => {
if(ok.messageCount > 0){
return ch.consume(USER_LOG_QUEUE, function(msg) {
if (msg !== null) {
ch.ack(msg);
writeToFile(msg.content.toString())
.then(rs => {
console.log(rs);
})
.catch(err => reject(err));
}
console.log('finished');
ch.close();
resolve(ok);
})
}else{
console.log('empty list : finished');
ch.close();
resolve(ok);
}
})
.then(ok => {
console.log('empty list2 : finished');
resolve(ok)
})
.catch(err => reject(err));
}catch(err){
reject(err);
}
});
via kenlz
No comments:
Post a Comment