The best practices article from Azure docs recommends reusing QueueClient to send multiple messages to obtain faster performance. https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-performance-improvements#reusing-factories-and-clients
I have a scenario of request-response messaging where Azure function is sending responses after being triggered by a service bus queue trigger (which is a request message). The performance of QueueClient.SendAsync is slow (1.5 to 3 seconds) if I create a new QueueClient everytime the function executes.
If I reuse the QueueClient in a static variable then the SendAsync time reduces to 50ms for later calls. However, the static reference does not seem to be a reliable way of reusing QueueClient connection, since I do not know when to close it.
Is there a reliable way to reuse and then close the QueueClient across multiple function executions? Can Azure-Function runtime provide any event where I can reliably close the queue client?