Remove a consumer in RabbitMQ with nodeJS
<p>I am trying to my listener to listen the queue only 1 message after what i want to remove my consumer instantly. How can i achieve this.
here is the code.</p>

<pre><code>  queueListener:function(Queue,timeOut){
    var deferred=sails.promise.defer(),timer,data;
    sails.amqp.connect('amqp://localhost', function(err, conn) {
      conn.createConfirmChannel(function(err, ch) {
        if(err){
          conn.close();
          deferred.reject(err);
        }else{
          ch.assertQueue(Queue, {durable: true});
          ch.prefetch(1);
          ch.consume(Queue,function(msg){
            data=msg.content.toString();
            clearTimeout(timer);
            ch.ack(msg);
            setTimeout(function(){
              conn.close();
              deferred.resolve(data);
            },0);
          },{noAck: false});
        }
      });
      timer=setTimeout(function(){
        conn.close();
        deferred.reject(new Error("Nothing in the Queue."));
      },timeOut-5);
    });
    return deferred.promise;
  }
</code></pre>

<p>in the above <strong>Queue</strong> is the queue it will be listening and timeOut represents how long my listener will be listening.
If it listens a message i want to stop listening.And for further listening i will be invoking the function <strong>queueListner</strong> next time.
Though i have made <code>conn.close()</code> but at the UI it still shows consumer.
<a href="https://i.stack.imgur.com/tKS19.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tKS19.png" alt="enter image description here"></a></p>