python – Why does rabbitmq disconnect with a long task?

Question:

Why does rabbitmq disconnect with a long task?

credentials = pika.PlainCredentials(rabbitmqConf['user'], rabbitmqConf['password'])
parameters = pika.ConnectionParameters(rabbitmqConf['host'], rabbitmqConf['port'], '/', credentials, socket_timeout=20)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue=rabbitmqConf['queueName'], durable=True)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback, queue=rabbitmqConf['queueName'])
channel.start_consuming()

When executing a long command (~ 10 min) and when calling

ch.basic_ack(delivery_tag=method.delivery_tag)

pymongo throws the following error

(-1, "ConnectionResetError(10054, 'Удаленный хост принудительно разорвал существующее подключение', None, 1005

Answer:

This error code means that the connection was dropped for some reason. For example, inactivity or network problems.

Catch the exception and try the connection again. After that, you will receive the last unconfirmed task.

Scroll to Top
AllEscort