var amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function(err, conn) {
    conn.createChannel(function(err, ch) {
        var q = 'task_queue';

        ch.assertQueue(q, {durable: false});
        ch.prefetch(1);
        console.log("[*] waiting for message in %s, to exit press CTRL+C", q);
        ch.consume(q, function(msg) {
            var secs = msg.content.toString().split('.').length - 1;

            console.log("[x] Received %s", msg.content.toString());
            setTimeout(function() {
                console.log(" [x] Done");
                ch.ack(msg);
            }, secs * 1000);
        }, {noAck: false});
    });
});