I'm trying to pull a single message off of rabbitmq, process it, and acknowledge that single message. I don't want it to continue after acknowledgement pulling messages off the queue. If I don't do ch.close() in the code below, it continues to pull messages after acknowledging the previous message.
Using a docker RabbitMQ instance I've set up this code (which works) but I'm curious if open/closing channels quickly are the best way to do this:
amqp.connect('amqp://guest:guest@localhost', (err, conn) => {
conn.createChannel((err, ch) => {
if (err) {
console.error(err);
} else {
let q = 'my queue';
ch.prefetch(1);
ch.consume(q, data => {
console.log(data.content.toString());
ch.ack(data);
ch.close();
returnData = data;
});
}
});
});