我使用 puka python 库来连接一些连接到 RabbitMQ 的客户端,当连接不使用时,这些客户端会在一段时间后超时。当前的 puka API 仅提供连接,不支持重新连接。我尝试使用正常的连接函数,但由于我覆盖了 _client 和 promise 变量,我收到了错误。如何在不中断其他连接的情况下将进程重新连接到 rabbitMQ?谢谢!
当前代码如下所示,并被多个进程使用:
_client = puka.Client(amqp_url=URL)
promise = _client.connect()
_client.wait(promise)
promise = _client.exchange_declare(exchange='notifications')
_client.wait(promise)
promise = _client.queue_declare(queue=_queue, durable=True)
_client.wait(promise)
promise = _client.queue_bind(exchange='notifications', queue=_queue, routing_key=_queue)
_client.wait(promise)
consume_promise = _client.basic_consume(queue=_queue)
while not CONDITION:
try:
result = _client.wait(consume_promise, timeout=1)
if not result:
continue
except puka.ConnectionBroken as e:
# An error is raised here when it disconnects from Rabbit
continue
_client.basic_ack(result)