heartbeat with URLParameters

122 views
Skip to first unread message

Vivek Sharma

unread,
Jul 18, 2021, 6:51:20 PM7/18/21
to rabbitmq-users
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)

jo...@cloudamqp.com

unread,
Jul 19, 2021, 12:56:26 PM7/19/21
to rabbitmq-users
Hi,

set 'my CloudAMQP URL' to "amqps://user:pas...@server-name.rmq.cloudamqp.com/vhost?heartbeat=XXXX" where XXXX is the heartbeat you want.
Feel free to contact us at sup...@cloudamqp.com if you need more guidance.

/Johan
Reply all
Reply to author
Forward
0 new messages