I'm using the below as my producer.py in a Flask application; once the application is idle for a bit, I first get the pika.exceptions.StreamLostError, and then the connection closes. Based on some research, I understand that the heartbeat setting might be a solution, however I could not find any references to how to set that when using URLParameters().
Any guidance will be much appreciated.
Thank you
______________________
import pika, json
params = pika.URLParameters('my CloudAMQP URL')
params.socket_timeout = 5
param.heartbeat = 5 # (I tried this, however it does not seem to have worked)
connection = pika.BlockingConnection(params)
channel = connection.channel()
# Declaring the queue
channel.queue_declare(queue="admin", durable=False, exclusive=False, auto_delete=False)
# Enabled delivery confirmations.
channel.confirm_delivery()
def publish(method, body):
properties = pika.BasicProperties(method)
channel.basic_publish(exchange='', routing_key='admin', body=json.dumps(body), properties=properties)