环境为1.2.0的pika版本,参考官方demo提示channel.basic_consume获得的参数错误got multiple values for keyword argument ‘queue’ 或者别的错误。
有查询过很多方法,比如版本回退,或者由于版本不同需要修改参数位置都是都不太奏效。
把官方文档1.2.0的版本翻出来检查了一下
basic_consume(queue, on_message_callback, auto_ack=False, exclusive=False,
consumer_tag=None, arguments=None, callback=None)[source]
Sends the AMQP 0-9-1 command Basic.Consume to the broker and binds messages for the consumer_tag to the consumer callback. If you do not pass in a consumer_tag, one will be automatically generated for you. Returns the consumer tag.
Parameters:
queue (str) – The queue to consume from. Use the empty string to specify the most recent server-named queue for this channel
on_message_callback (callable) –
The function to call when consuming with the signature on_message_callback(channel, method, properties, body), where
channel: pika.channel.Channel
method: pika.spec.Basic.Deliver
properties: pika.spec.BasicProperties
body: bytes
参考这个接口的介绍,加进去之后会提示未知的参数 on_message_callback或者参数位置不正确。
然后测试了许久才发现这是一个坑
实际上的顺序应该是
basic_consume(on_message_callback,queue,****)
最后代码
channel.basic_consume(on_message_callback=callback,queue='hello',autoack=True)
可用