ypeError: basic_consume() got multiple values for argument 'queue'

#author:Yuan Lei
import pika
conection = pika.BlockingConnection(pika.ConnectionParameters('192.168.5.158'))
channel = conection.channel()

#生产者已经声明了这个queue,为什么消费者还需要声明?
#如果已经知道生产者已经运行了,说明这个queue已经存在了,那么这里可以不声明。
#如果生产者没有声明这个queue(没有运行),那么消费者就需要声明这个queue,否则会报错。
channel.queue_declare(queue='hello')

#ch:channel,管道的名字
def callback(ch,method,properties,body):
print('--->',ch,method,properties)
print('[x] recv %r'%body)


# 开始消费消息
channel.basic_consume(
callback,#如果收到消息就调用callback函数来处理消息
queue='hello', #从hello队列收消息
no_ack=True)

#等待收消息,执行CTRL+c关闭
print("[*] waiting for messages.To exit press CTRL+C ")

运行报错:

 

 原因:参数位置错误。

解决办法:

channel.basic_consume(
callback,
queue='hello',
no_ack=True)
改为:
channel.basic_consume(
‘hello’,#从hello队列接收消息
callback,#如果收到消息就调用callback函数来处理消息
Flase)
posted @ 2022-10-31 10:40  园来是伱  阅读(82)  评论(0编辑  收藏  举报