[rabbitmq-discuss] Pika problem, channel starts consuming before I call start_consuming(), then raises Queue.DeclareOk KeyError
    Aaron Voelker 
    aaron at contextlogic.com
       
    Wed Sep 21 22:26:59 BST 2011
    
    
  
Environment: Python 2.6.6, Ubuntu 10.10, Pika 0.95. I have reproduced
this problem on several machines with the same specs.
Description of Test: Publish to test1, then consume from test1 and
test2.
What Happens: The queue with the message begins consuming before I
have even told it to start_consuming. Pika seems to get into a weird
state, and then throws a Queue.DeclareOk KeyError.
"""
In Callback Hello World
Traceback (most recent call last):
  File "./rabbittests.py", line 31, in <module>
    channel.queue_declare(queue=queue_name)
  File "/usr/local/lib/python2.6/dist-packages/pika/spec.py", line
2437, in queue_declare
    [Queue.DeclareOk])
  File "/usr/local/lib/python2.6/dist-packages/pika/adapters/
blocking_connection.py", line 221, in rpc
    frame = self._frames[reply]
KeyError: 'Queue.DeclareOk'
"""
The Code:
#!/usr/bin/python
import pika
######### Producer Code
connection =
pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
for queue_name in ('test1', 'test2'):
    channel.queue_declare(queue=queue_name)
channel.basic_publish(exchange='', routing_key='test1', body='Hello
World')
connection.close()
######### Consumer Code
connection =
pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
def callback(ch, method, properties, body):
    print "In Callback", body
    ch.basic_ack(delivery_tag = method.delivery_tag)
for queue_name in ('test1', 'test2'):
    channel.queue_declare(queue=queue_name)
    channel.basic_consume(callback, queue=queue_name)
assert False # NOTE: this doesn't execute!
channel.start_consuming()
    
    
More information about the rabbitmq-discuss
mailing list