I have this snippet in a code that is running on a Function App:
from azure.servicebus import ServiceBusClient, ServiceBusMessage
client = ServiceBusClient.from_connection_string('<conn_string>')
sender = client.get_topic_sender('<topic>')
sender.send_messages(ServiceBusMessage('<message>', subject='<subject>'))
Each time I try to send a message after the function is idle for a few minutes, the function seems to take much longer. I'm not very familiar with the mechanism of how this works, but it seems that the client or topic sender is reconnecting.
How can I keep this sender alive so that it won't take such a long time?
sender.renew_sender()
every 10 minutes will ensure a continuous connection.MyServiceBusClient
class that connects to Azure Service Bus using a connection string and sends a message to a topic.send_message_to_topic()
function sends a message to the topic using thesender
object.Code with
send_messages()
:Output:
Azure:
Scheduler a timer to execute the function periodically: