azure-functionsazure-queuesazure-storage-explorer

Message not added to Azurite Queue from Azure Function


Following the documentation below I trying to create an azure function which adds a message to a queue.

https://learn.microsoft.com/en-us/azure/azure-functions/functions-add-output-binding-storage-queue-vs?tabs=in-process#add-an-output-binding

The code gets triggered and executes with out an error, but I could not see any message in the Azure Storage Explorer Queue.

I added Azurite Storage account to my local Storage Explorer. But the queue does not get created and the message is not getting added.

AzureWebJobsStorage is set to "UseDevelopmentStorage=true".

How do I test this locally in the storage explorer? What are the steps and what all do I need?


Solution

  • I tried to reproduce the issue by following steps:

    1. Created Azure Functions (Stack: .Net Core 3.1 - Http Trigger) in Visual Studio.
    2. Installed this package Microsoft.Azure.WebJobs.Extensions.Storage through Nuget Package Solution to the Project.
    3. Added the Output Queue binding to the Task static method like:

    public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, [Queue("outqueue"), StorageAccount("AzureWebJobsStorage")] ICollector<string> msg, ILogger log)

    Added the code which writes the passed parameter in the function URL to the output queue (before parsing the response message code):

    if (!string.IsNullOrEmpty(name))
        {
        // Add a message to the output collection.
        msg.Add(string.Format("Name passed to the function: {0}", name));
        }
    

    Now the full code looks is:

    enter image description here

    local.settings.json

    {
        "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",
            "FUNCTIONS_WORKER_RUNTIME": "dotnet"
        }
    }
    
    1. Run the function locally and copy the function URL that comes in the console to the browser along with parameters like: http://localhost:7071/api/Function1?name=HariKrishna Then it should be displayed in the browser as Hello, HariKrishna. This HTTP triggered function executed successfully.

    2. Go to the Storage Explorer > Expand Queues and refresh it (right-click on queues and click refresh) to see the queue created by functions runtime while a function is running and refresh the output queue also to see the messages as you can the console output, browser output and Queue messages in below screenshot:

    enter image description here

    enter image description here