Rabbit MQ StreamLostError with python pika library

Viewed 2187

When I listen my queue with python pika library, I always get StreamLostError and my code crushes.

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()  
2 Answers
Related