AZFunc and Azure Bus: The listener for function was unable to start

Claude VERNIER 41 Reputation points
2024-03-14T16:10:32.9233333+00:00

I'm working on an Azure Function triggered by a queue on a Service bus.

When working on localhost, the function never gets triggered but there is no error.

On Azure, I get from the logs: The listener for function 'Functions.Receive' was unable to start.

My function looks like:

	[Function("Receive")]
	public string Receive([ServiceBusTrigger("acme", Connection = "POC_BUS")] string mySbMsg)
	{
		string msg;
		try
		{
			msg = "Message received = " + mySbMsg;
		}
		catch (Exception ex)
		{
			msg = ex.Message;
		}
		return msg;
	}

My local.settings.json file has:

	{
	  "IsEncrypted": false,
	  "POC_BUS:fullyQualifiedNamespace": "myacmebus.servicebus.windows.net",
	  "POC_BUS__fullyQualifiedNamespace": "myacmebus.servicebus.windows.net",
	  "WEB_PROXY": "http://myproxy.acme.com:443",
	
	  "Values": {
	    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
	    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
	    "APPINSIGHTS_INSTRUMENTATIONKEY": "21a...3bd",
	
	    "POC_BUS:fullyQualifiedNamespace": "myacmebus.servicebus.windows.net",
	    "POC_BUS__fullyQualifiedNamespace": "myacmebus.servicebus.windows.net",
	    "WEB_PROXY": "http://myproxy.acme.com:443",
	  }
	}

I'm working with VS2022, a .Net 7 project with these dependencies:

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.10.4" />
    <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.17.4" />
    <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.6.0" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.14.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.7.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.10.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
  </ItemGroup>

I could extract those logs:

Job host stopped
Stopping JobHost
The listener for function 'Functions.Receive' was unable to start.
Retrying to start listener for function 'Functions.Receive' (Attempt 10)
...
Retrying to start listener for function 'Functions.Receive' (Attempt 2)
Host lock lease acquired by instance ID '53...c7'.
Retrying to start listener for function 'Functions.Receive' (Attempt 1)
Worker process started and initialized.
Host started (608ms)
Job host started
"HttpOptions
{
  ""DynamicThrottlesEnabled"": false,
  ""EnableChunkedRequestBinding"": false,
  ""MaxConcurrentRequests"": -1,
  ""MaxOutstandingRequests"": -1,
  ""RoutePrefix"": ""api""
}"
Host initialized (237ms)
"Initializing function HTTP routes
Mapped function route 'api/Hello' [get,post] to 'Hello'
Mapped function route 'api/Post' [get,post] to 'Post'
Mapped function route 'api/Read' [get,post] to 'Read'
Mapped function route 'api/ReadAzure' [get,post] to 'ReadAzure'
Mapped function route 'api/Write' [get,post] to 'Write'
Mapped function route 'api/WriteAzure' [get,post] to 'WriteAzure'"
The 'AutoCompleteMessages' option has been overriden to 'True' value for 'Functions.Receive' function.
"Found the following functions:
Host.Functions.Hello
Host.Functions.Post
Host.Functions.Read
Host.Functions.ReadAzure
Host.Functions.Receive
Host.Functions.Write
Host.Functions.WriteAzure"
Generating 7 job function(s)
7 functions loaded
2 functions found (Custom)
Reading functions metadata (Custom)
Loading functions metadata
Starting Host (HostId=myFunc, InstanceId=16...831, Version=4.30.0.22097, ProcessId=nnnn, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=~4)
Starting JobHost

From Azure portal:

I granted bus receiver role to my account and to azure function managed identity.

In console window of the azure function, I did "curl https://myacmebus.servicebus.windows.net/acme" and got a red message showing the amount of messages received and xferd and average speed so it seems the function has access.

I defined: POC_BUS/fullyQualifiedNamespace, POC_BUS:fullyQualifiedNamespace and POC_BUS__fullyQualifiedNamespace with  "myacmebus.servicebus.windows.net"

I really have two issues as it doesn't work either on local or on Azure but the one on Azure is my prioriy now.

If you could help, I'd appreciate as I have no idea what to try anymore.

Claude

Azure Service Bus
Azure Service Bus

An Azure service that provides cloud messaging as a service and hybrid integration.

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.