简体   繁体   English

带有 python 鼠兔库的 Rabbit MQ StreamLostError

[英]Rabbit MQ StreamLostError with python pika library

When I listen my queue with python pika library, I always get StreamLostError and my code crushes.当我使用 python 鼠兔库收听我的队列时,我总是得到 StreamLostError 并且我的代码崩溃了。

In my code, I must listen the queue forever without exception and I must get messages 1 by 1.在我的代码中,我必须无一例外地永远监听队列,并且我必须一条一条地获取消息。

Here is my code(I simplified it).这是我的代码(我简化了它)。

def callback(ch, method, properties, body):
   ch.basic_ack(delivery_tag = method.delivery_tag)
   #doing work here, it gets minimum 5 minutes, sometimes maximum 1 hour

credentials = pika.PlainCredentials(username, password)
parameters = pika.ConnectionParameters(ip, port, '/', credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.basic_qos(prefetch_count=1)
channel.queue_declare(queue=queuename, durable=True)
channel.basic_consume(queue=queuename, on_message_callback=callback, auto_ack=False)
channel.start_consuming()  

try to set connection_attempts and retry_delay parameters in the request if you are using pika URLParameters.如果您使用 pika URLParameters,请尝试在请求中设置 connection_attempts 和 retry_delay 参数。 Look down the below link for more information.In my case I added ?connection_attempts=20&retry_delay=1 after the AMPQ https://pika.readthedocs.io/en/stable/modules/parameters.html#urlparameters查看以下链接以获取更多信息。在我的例子中,我在 AMPQ https 之后添加了?connection_attempts=20&retry_delay=1 ://pika.readthedocs.io/en/stable/modules/parameters.html#urlparameters

The problem is that your work takes too long and blocks Pika's I/O loop.问题是你的工作时间太长并且阻塞了 Pika 的 I/O 循环。 This causes heartbeats to be missed, and RabbitMQ thinks your connection is dead.这会导致心跳丢失,RabbitMQ 认为您的连接已死。

Please see this code for one correct way to do long-running work:请参阅此代码以了解进行长时间运行的一种正确方法:

https://github.com/pika/pika/blob/master/examples/basic_consumer_threaded.py https://github.com/pika/pika/blob/master/examples/basic_consumer_threaded.py


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.注意: RabbitMQ 团队会监控rabbitmq-users邮件列表,并且只是偶尔在 StackOverflow 上回答问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一旦 pika 库中的消息队列为空,如何停止 Rabbit MQ 中的消费者? - How to stop consumer in Rabbit MQ once the message queue is empty in pika library? 获取 pika.exceptions.StreamLostError:传输使用 pika 运行 python 脚本 docker 图像时指示 EOF - Getting pika.exceptions.StreamLostError: Transport indicated EOF while running python script docker image which using pika 在python(pika库)中并行运行代码 - run code in parallel in python (pika library) 鼠兔连接丢失错误:pika.exceptions.StreamLostError: Stream 连接丢失:ConnectionResetError(104, 'Connection reset by peer') - Pika connection lost Error: pika.exceptions.StreamLostError: Stream connection lost: ConnectionResetError(104, 'Connection reset by peer') 使用 Python 将 Rabbit mq 消息保存到 Azure 存储中 - Saving Rabbit mq messages into Azure storage using Python 使用 Python 鼠兔库合并 RabbitMQ 队列的最佳方法是什么? - What is the best way to merge RabbitMQ queues using Python pika library? RabbitMQ-pika-Rabbit.js-node.js - RabbitMQ - pika - rabbit.js - node.js 如何将消息添加回Rabbit MQ? - How to add message back to Rabbit MQ? 兔子MQ重新启动后,使用者不重新连接 - Consumers do not reconnect after Rabbit MQ restart 尝试将消息发布到Rabbit MQ服务器 - Trying to publish messages to rabbit mq server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM