Python Kombu消费者未收到rabbitmq消息的通知(queue.get不起作用)

Python Kombu消费者未收到rabbitmq消息的通知(queue.get不起作用),python,rabbitmq,amqp,Python,Rabbitmq,Amqp,如果我运行以下代码,将永远不会触发传递给的回调(测试) 但是,如果我关注rabbitmq GUI,我会看到消息已被检索(但未被确认)。因此,消费者似乎收到了信息,但没有将其传递给我的回调。如果我将no_ack设置为true,则消息将从队列中消失,再次不调用回调 hn = "..." usr = "..." pwd = "..." vh = "/" port = 5672 rkey = "some.routing.key" qname = "some-queue-name" exchangeNam

如果我运行以下代码,将永远不会触发传递给的回调(测试)

但是,如果我关注rabbitmq GUI,我会看到消息已被检索(但未被确认)。因此,消费者似乎收到了信息,但没有将其传递给我的回调。如果我将no_ack设置为true,则消息将从队列中消失,再次不调用回调

hn = "..."
usr = "..."
pwd = "..."
vh = "/"
port = 5672
rkey = "some.routing.key"
qname = "some-queue-name"
exchangeName = "MyExchange"

connection = BrokerConnection(hostname=hn,
                              userid=usr,
                              password=pwd,
                              virtual_host=vh,
                              port=port)

connection.connect()
ch = connection.channel()

# Create & the exchange
exchange = Exchange(name=exchangeName,
              type="topic",
              channel=ch,
              durable=True)

exchange.declare()

# Temporary channel
ch = connection.channel()

# Create the queue to feed from
balq = Queue(name=qname,
              exchange=exchange,
              durable=True,
              auto_delete=False,
              channel=ch,
              routing_key=rkey)        

# Declare it on the server
balq.declare();

def test(b,m):
    print '** Message Arrived **'

# Create a consumer
consumer = Consumer(channel=connection.channel(),
                    queues=balq,
                    auto_declare=False,
                    callbacks = [test]
                    )

# register it on the server
consumer.consume(no_ack=False);

print 'Waiting for messages'
while(True):
    pass
但是,以下代码工作正常(我可以成功获取并确认消息):


但关键是保持异步。所以我的回调肯定有问题。

结果是一个简单的错误。添加

connection.drain_events()
发送到while循环会导致消息到达

connection.drain_events()