我尝试使用pika来做最基本的rabbitmq连接,队列声明,发送单个消息和接收单个消息。
看起来pika是非阻塞的,并且对dockerized rabbit的背靠背API调用会导致竞争条件。
举例来说:
channel.queue_declare(queue_name)
time.sleep(5)
channel.queue_bind(queue=queue_name, exchange=queue_params.exchange,
routing_key=queue_params.routing_key)
网元成功
然而,在这方面,
channel.queue_declare(queue_name)
channel.queue_bind(queue=queue_name, exchange=queue_params.exchange,
routing_key=queue_params.routing_key)
在queue_bind
上失败,
pika.exceptions.ChannelClosedByBroker: (404, "NOT_FOUND - no exchange 'fleet' in vhost '/'")
尝试busy-wait:
def on_declare_ok():
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)
print(f"Attempting to declare {queue_name}")
channel.queue_declare(queue_name)
print(f"Successfully declared {queue_name}")
on_declare_ok()
也没有好处,这进入了一个无限循环,
Attempting to bind queue_name
我希望鼠兔能在内部处理所有这些事情,我想我做错了什么。
我在其他pika API调用中也遇到了这些竞争条件,尽管所有东西都是单线程的(除了在另一个docker容器中运行的rabbit服务器)。
用鼠兔做拦网最好的方法是什么?
1条答案
按热度按时间1zmg4dgp1#
错误提示:在您尝试绑定队列时,您的exchange不存在: