根据文档,应该支持回调参数。也是根据源代码。
我在做
def declare_ok(method: pika.frame.Method):
while True: # TODO busy waiting until a better way is found
try:
print(f"Attempting to bind {queue_name}")
channel.queue_bind(queue=queue_name, exchange=queue_params.exchange,
routing_key=queue_params.routing_key)
print(f"Successful bind to {queue_name}")
break
except pika.exceptions.ChannelClosedByBroker as ex:
time.sleep(0.1)
except pika.exceptions.ChannelWrongStateError as ex:
time.sleep(0.1)
channel.queue_declare(queue_name, callback=declare_ok)
并且得到
TypeError: queue_declare() got an unexpected keyword argument 'callback'
传递回调的正确方法是什么?
如果您使用最新版本的
pika
(v 1.3.2),BlockingChannel.queue_declare()
函数签名已更改以删除 callback
参数。请参阅此处的文档:https://github.com/pika/pika/blob/f4d8f8ff02a4da4653749c86161b7d52e53f73fe/pika/adapters/blocking_connection.py#L2483