kombu消息消息消失

时间:2016-01-09 22:49:16

标签: python python-2.7 rabbitmq kombu

我有这段代码:

from kombu.transport import pyamqp
from kombu import Connection, Exchange, Queue, Producer, Consumer

transport = pyamqp
vhost = '/'
host = '127.0.0.1'
port = '5672'
usr = 'guest'
pwd = 'guest'

conn = Connection(virtual_host=vhost, hostname=host, port=port, userid=usr, password=pwd)
chan = conn.channel()

exchange = Exchange(name='ami_exch', type='topic', channel=chan, durable=True, auto_delete=True, delivery_mode='persistent')
exchange.declare(nowait=False)

q_ctl = Queue(name='ami.ctl', channel=chan, exchange=exchange, routing_key='ami.ctl.#', durable=True, auto_delete=True, exclusive=False)
q_ctl.declare(nowait=False)
q_str = Queue(name='ami.str', channel=chan, exchange=exchange, routing_key='ami.str.*', durable=True, auto_delete=True, exclusive=False)
q_str.declare(nowait=False)

msg = exchange.Message("Test MQ message.")
exchange.publish(message=msg, routing_key='ami.ctl')
exchange.publish(message=msg, routing_key='ami.str.send')

a = []
def tst(body, message):
    a.append(body)

consumer = Consumer(channel=chan, queues=[q_ctl,q_str], auto_declare=False, no_ack=True, callbacks=tst)
consumer.consume()
print a

在我运行consumer.consume()之后 - 我的a变量仍然是一个空列表,但是在rabbitmq队列中现在是空的,这意味着它们被消耗了。

进一步尝试将更多消息放入队列是没有意义的,因为队列保持为空,就像我没有连接或消息被直接消费一样。

我做错了什么?

0 个答案:

没有答案