AMQPlib callback API. Завершение consume по таймауту
Есть вот такой простой код. Но нужно, чтобы consume завершался через определённое время.
Пробовал ставить таймаут на соединение(10000), но это оказывается таймаут на рукопожатие.
Важно, не использовать setTime и setInterval
Какие есть варианты и идеи, как можно завершить consume или закрыть соединение через определённое время?
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', {timeout: 10000},function(error0, connection) {
if (error0) {
throw error0;
}
connection.createChannel(function(error1, channel) {
if (error1) {
console.log("ERROR")
console.log(error1)
throw error1;
}
var queue = 'task_queue';
channel.assertQueue(queue, {
durable: true
});
channel.prefetch(1);
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", queue);
channel.consume(queue, function(msg) {
channel.ack(msg);
var secs = msg.content.toString().split('.').length - 1;
console.log(" [x] Received %s", msg.content.toString());
}, {
noAck: false
});
});
/*
setTimeout(function() {
console.log("TIMEOUT")
connection.close();
process.exit(0)
}, 10000);
*/
});