Hello REETHU H G,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are facing an issue where, even after deploying your Azure Function successfully via Visual Studio Code, the function does not trigger on Service Bus queue messages, and the log stream reports: “Listener function 'function_name' was unable to start.”
So sorry for that but, successful deployment does not mean you should be able to read. Because, listener startup failures are often due to configuration issues and deployment success does not imply runtime success.
This is not simply a deployment glitch but typically indicates that the Azure Function runtime is unable to establish a connection to the Service Bus resource, often due to misconfiguration in application settings or incorrect use of the trigger binding. While there are no errors in your code, the fact that the listener fails to start points to environmental or configuration-based blockers, particularly concerning your connection strings or the Function App’s runtime setup.
Therefore, beyond correcting the configuration, the best practice for your scenario includes:
- Verify Function Runtime Type (In-Process or Isolated) to determine if your Azure Function is using the in-process model (
Microsoft.NET.Sdk.Functions
) or the isolated worker model (Microsoft.Azure.Functions.Worker
). - https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide
After you confirmed the above, you will need to configure the correct connection String Format:
- For in-process, use this format in your code and Azure Application Settings:
[ServiceBusTrigger("myqueue", Connection = "ServiceBusConnection")]
- App Settings:
`` `ServiceBusConnection = Endpoint=sb://...` ``
- For isolated worker, you must define a structured setting:
`` `ServiceBusConnection__fullyQualifiedNamespace = your-namespace.servicebus.windows.net` ``
`ServiceBusConnection__credential = connectionString`
`ServiceBusConnection__connectionString = Endpoint=sb://...`
For more reading on isolated workers - https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#use-service-bus-trigger
- Deploy configuration to Azure properly, to ensure that the connection string is not just in
local.settings.json
, but also added under Azure Portal > Function App > Configuration > Application settings. - https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings - Try to check Runtime Version and Worker Configuration. If your Function App should use a compatible runtime. For .NET 6/7, the
FUNCTIONS_WORKER_RUNTIME
must be set todotnet-isolated
in app settings. - https://learn.microsoft.com/en-us/azure/azure-functions/functions-versions - Confirm required NuGet Packages to ensure that your project includes the correct NuGet package:
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.x.x" />
- With the above, if the listener still fails, use Application Insights or the Log Stream to get detailed startup logs. Look for repeated errors or retry attempts which suggest network or credential issues. - https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitoring
- For deeper diagnostics, access the Kudu console at:
`https://<your-function-app-name>.scm.azurewebsites.net/DebugConsole`
Navigate to:`/LogFiles/Application/Functions/Function/<YourFunctionName>`
and review the listener logs. For more details check - https://github.com/projectkudu/kudu/wiki - For production workloads, especially on consumption plan, you may add a
TimerTrigger
function to reduce cold starts:
[Function("KeepAlive")]
public static void Run([TimerTrigger("0 /5 ")] TimerInfo myTimer, FunctionContext context)
{
var logger = context.GetLogger("KeepAlive");
logger.LogInformation("Keep-alive executed at: {time}", DateTime.Now);
}
I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.