node.jsazure-functionsazure-servicebus-queues

Getting error "The listener for function 'Functions.functionname' was unable to start." for Servicebus trigger using node.js


I am getting error "The listener for function 'Functions.functionname' was unable to start." for ServiceBus trigger function after deploying in azure functions cloud. Please help to resolve this.

Thanks in advance

Anish

This issue is not getting in local environment. And this issue not getting for other functions created earlier.


Solution

  •  Retrying to start listener for function 'Functions.cancelOrder'
     (Attempt 383) 2023-06-05T02:16:11Z [Error] The listener for function'Functions.cancelOrder' was unable to start
    

    This is a common error that occurs when your Local Function is not connected to either Azure Storage account or if you are doing a local development and do not want to use Azure storage account you need to have Azure storage emulator running in the background. Also, if you're not connected to correct Service bus namespace.

    I tried creating one sample Azure Service bus Function app and it was created successfully.

    1) With Azure Storage Account and Service bus connection string:-

    I created one Service Bus namespace and one queue like below:-

    enter image description here

    Created one Azure Storage account:-

    enter image description here

    Followed the steps below to create Azure Functions Service bus queue trigger:-

    Selected create Function from VS code Azure Function extension:-

    enter image description here

    Selected Javascript as language:-

    enter image description here

    Model v3:-

    enter image description here

    Azure Service Bus Queue Trigger:-

    enter image description here

    Created local settings to connect to Service bus:-

    enter image description here

    Selected Service Bus Namespace like below:-

    enter image description here

    Entered the queue name I created earlier in my service bus for my function to connect to it:-

    enter image description here

    The Azure Service Bus Function is created Locally like below:-

    enter image description here

    Now, When I run this Function by either clicking on fn + f5 or Run > Start Debugging It will prompt me to either connect to Azure storage account or use Local storage emulator:-

    enter image description here

    For now I will click on Connect Storage account and select my Azure storage account like below:-

    enter image description here

    As, I have Azure Function Core tools and Azure Function extension installed in VS code, The Function ran successfully, Refer below:-

    enter image description here

    Now, I sent messages to Azure Service Bus queue and the Function was triggered:-

    enter image description here

    enter image description here

    My local.settings.json:-

    {
    
    "IsEncrypted": false,
    
    "Values": {
    
     "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=azurestrgaccount;AccountKey=xxxxxxxxOxS+ASt1bDRzw==;EndpointSuffix=core.windows.net",
    
     "FUNCTIONS_WORKER_RUNTIME": "node",
    
     "siliconfunc12_SERVICEBUS": "Endpoint=sb://siliconfunc12.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=xxxxx5yHisbsUxxxxx"
    
     }
    
    }
    

    I deployed the above Function in Azure Function app and the deployment was successful, Refer below:-

    enter image description here

    enter image description here

    Function got deployed successfully, Refer below:-

    enter image description here

    enter image description here

    2) By using Local storage emulator:-

    You can download the Storage Emulator in your local machine from this Link.

    I followed the same steps as above just while running the function I used Local Emulator after starting the Local Emulator downloaded from the link above:-

    Opened Emulator like below:-

    enter image description here

    Emulator started:-

    enter image description here

    Now, I selected Local Emulator and the Function was triggered successfully, Refer below:-

    enter image description here

    enter image description here

    enter image description here

    My local.settings.json:-

    {
    
    "IsEncrypted": false,
    
    "Values": {
    
     "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    
     "FUNCTIONS_WORKER_RUNTIME": "node",
    
     "siliconfunc12_SERVICEBUS": "Endpoint=sb://siliconfunc12.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=xxxxxHisbsUxp47+ASbMxxxx"
    
     }
    
    }
    

    I tried deploying this Function in Azure Function app and it was successful too:-

    enter image description here

    If the error persists, Make sure you delete the existing Azure Functions Core tools from this path - C\Program Files\Microsoft\Azure Functions Core Tools. and install the newer version of Azure Function core tools by referring this Link.

    My Azure Functions Core tools version:-

    func -v
    4.0.5148
    

    enter image description here

    Node.js version:-

    node -v
    v18.16.0
    

    Storage emulator version:-

    5.10.0.0
    

    enter image description here

    Along with this Make sure you have below extensions installed in your VS Code:-

    enter image description here

    enter image description here

    Make sure you also have Azurite extenstion installed:-

    enter image description here

    References:-

    python - The listener for function 'Functions.trigger' was unable to start? while running Azure function locally - Stack Overflow By venkateshdodda

    Listener for Azure function was unable to start error while running Azure function app locally. How to solve this? - Microsoft Q&A By MayankBargali-MSFT