title: Kombu ConsumerMixin close queue to prevent fanout data reception
body: <p>How do I close a Kombu ConsumerMixin queue connected to a fanout exchange so I don't accumulate data from the Publisher while my Consumer is not active?</p>
  
  <p>I'm using Kombu 3.0.24 (with RabbitMQ) in Python 2.7.</p>
  
  <p>Below is my code for the two classes.  I'd like these to be rather generic classes so I can reuse them for direct queues and RPC-like queries/replies.</p>
  
  <p>The problem is, if I stop and restart the consumer, old data is waiting for me in the consumer queue.  I assume this is because I need to delete the queue when I stop the consumer, but I can't figure out how.  Thanks.</p>
  
  <p>MessageConsumer.py</p>
  
  <pre><code>from kombu.mixins import ConsumerMixin
  from kombu import Queue, Exchange, Connection
  import logging
  
  class MessageConsumer(ConsumerMixin):
  
      def __init__(self,
                   broker='amqp://',
                   exchange='mExchange',
                   queue = 'mQueue',
                   type='direct',
                   no_ack=False):
          self.connection = Connection(broker)
          self.mExchange = Exchange(exchange, type=type)
          self.mQueue = Queue(queue, self.mExchange)
          self.mQueue.no_ack = no_ack
  
      def get_consumers(self, Consumer, channel):
          return [Consumer(queues=self.mQueue,
                           accept=['json'],
                           callbacks=[self.process_task])]
  
      def process_task(self, body, message):
          logging.debug('RECEIVED: {}'.format(body))
  
      def stop(self):
          self.should_stop = True
          self.connection.release()
  
  
  if __name__ == '__main__':
  
      mMessageConsumer = MessageConsumer(exchange='sensor_data',
                                         queue='rx1_queue',
                                         type='fanout',
                                         no_ack=True)
      try:
          mMessageConsumer.run()
      except KeyboardInterrupt:
          mMessageConsumer.stop()
  </code></pre>
  
  <p>MessagePublisher.py</p>
  
  <pre><code>from kombu import Queue, Exchange, Connection
  from kombu.pools import producers
  import logging
  
  class MessagePublisher(object):
  
      def __init__(self,
                   broker='amqp://',
                   exchange='mExchange',
                   type='direct',
                   no_ack=False):
          self.connection = Connection(broker)
          self.mExchange = Exchange(exchange, type=type)
  
      def publish(self, message, serializer='json', compression=None):
          with producers[self.connection].acquire(block=True) as producer:
              producer.publish(message,
                               serializer=serializer,
                               compression=compression,
                               exchange=self.mExchange,
                               declare=[self.mExchange]
                               )
  
      def close(self):
          self.connection.release()
  
  if __name__ == '__main__':
      mMessagePublisher = MessagePublisher(type='fanout',exchange='sensor_data')
      x=0
      while True:
          x += 1
          mMessagePublisher.publish(x)
      mMessagePublisher.close()
  </code></pre>
  
  <p>If there is a more efficient way for me to code this please suggest it.  Most of the examples I found by Googling use older versions of Kombu so it's hard for me to figure out the best implementation with 3.0.24.</p>