Skip to content

Commit a6b6886

Browse files
committed
Set heartbeat and timeout for RabbitMQ connections to improve stability
1 parent c4bf7c7 commit a6b6886

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ def publish_to_exchange(key: str, sub_key: str, data: dict) -> None:
166166
host=RABBITMQ_HOST,
167167
credentials=credentials,
168168
client_properties={"connection_name": "TwilioConnection"},
169+
# Set heartbeat to 300 seconds (5 minutes) to keep connection alive
170+
heartbeat=300,
171+
blocked_connection_timeout=300,
169172
)
170173
connection = pika.BlockingConnection(parameters)
171174
channel = connection.channel()
@@ -459,6 +462,9 @@ def consumer_thread() -> None:
459462
client_properties={
460463
"connection_name": "OutgoingSMSConsumerConnection"
461464
},
465+
# Set heartbeat to 300 seconds (5 minutes) to keep connection alive
466+
heartbeat=300,
467+
blocked_connection_timeout=300,
462468
)
463469
connection = pika.BlockingConnection(parameters)
464470
channel = connection.channel()

0 commit comments

Comments
 (0)