I have this code:
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
After I run consumer.consume()
- nothing happens in terms that my a
variable remains an empty list, but in the rabbitmq queues now are empty, meaning that they were consumed.
Further attempts to put more messages into the queues are pointless as queues remain empty as if I was not connected or messages are consumed straightaway.
What am I doing incorrectly?