'Consume from a server queue. Returns a Deferred that fires with a
tuple: (queue_object, consumer_tag). The queue object is an instance of
ClosableDeferredQueue, where data received from the queue will be
stored. Clients should use its get() method to fetch individual
message.'

def basic_consume(self, *args, **kwargs):

    if self.__closed:
        return defer.fail(self.__closed)
    queue = ClosableDeferredQueue()
    queue_name = kwargs['queue']
    kwargs['consumer_callback'] = (lambda *args: queue.put(args))
    self.__consumers.setdefault(queue_name, set()).add(queue)
    try:
        consumer_tag = self.__channel.basic_consume(*args, **kwargs)
    except:
        return defer.fail()
    return defer.succeed((queue, consumer_tag))
