Edit: I had the wrong version of the pika package installed on my device. It works fine after I updated from pip.
I just started learning the usage of RabbitMQ (using Python) by following their tutorial. The send.py
code works works fine but when I try to run receive.py
, I see this error:
Traceback (most recent call last):
File "receive.py", line 15, in <module>
no_ack=True)
TypeError: basic_consume() got multiple values for keyword argument 'queue'
Here's the code inside receive.py
:
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
channel.basic_consume(callback,
queue='hello',
no_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
Any idea what I am doing wrong?
You probably don't need it anymore, but I had exactly the same problem as You and this is what I figured out.
For me it turned out that RabbitMQ documentation must've been using a different version of pika. I found out that in pika 1.0.0 basic_consume function has different order of arguments. This is how it looks on my machine:
def basic_consume(self,
queue,
on_message_callback,
auto_ack=False,
exclusive=False,
consumer_tag=None,
arguments=None):
Once I changed the order of arguments passed, or added keyword 'on_message_callback=callback' it all worked. I hope it helps!
just change
channel.basic_consume(callback, queue='hello', no_ack=True)
to
channel.basic_consume('hello', callback, auto_ack=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With