Message not added to Azure Queue from Azure Function

Newbie Dev 151 Reputation points
2021-12-21T13:49:39.54+00:00

Hi,

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

https://video2.skills-academy.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?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,572 questions
Azure Storage Explorer
Azure Storage Explorer
An Azure tool that is used to manage cloud storage resources on Windows, macOS, and Linux.
240 questions
Azure Queue Storage
Azure Queue Storage
An Azure service that provides messaging queues in the cloud.
99 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jaliya Udagedara 2,821 Reputation points MVP
    2021-12-21T18:22:10.51+00:00

    I am not sure which Azure Functions Programming Model you are using (In Process vs Isolated). Since Isolated is the way forward, follow these steps.

    Create Azure Functions Project
    159364-image.png

    Note: Visual Studio 2022 will automatically start Azurite Services.
    159398-image.png

    Right-click on Connected Services and click on Manage Connected Services. Note Storage Azurite emulator is already set up.
    159404-image.png

    Update the HTTP Trigger function as follows.

    using Microsoft.Azure.Functions.Worker;  
    using Microsoft.Azure.Functions.Worker.Http;  
    using Microsoft.Extensions.Logging;  
    using System.Net;  
      
    namespace FunctionApp1  
    {  
        public class Function1  
        {  
            private readonly ILogger _logger;  
      
            public Function1(ILoggerFactory loggerFactory)  
            {  
                _logger = loggerFactory.CreateLogger<Function1>();  
            }  
      
            [Function("Function1")]  
            public MultiResponse Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)  
            {  
                _logger.LogInformation("C# HTTP trigger function processed a request.");  
      
                var message = "Welcome to Azure Functions!";  
      
                var response = req.CreateResponse(HttpStatusCode.OK);  
                response.Headers.Add("Content-Type", "text/plain; charset=utf-8");  
                response.WriteString(message);  
      
                // Return a response to both HTTP trigger and storage output binding.  
                return new MultiResponse()  
                {  
                    // Write a single message.  
                    Messages = new string[] { message },  
                    HttpResponse = response  
                };  
            }  
        }  
      
        public class MultiResponse  
        {  
            [QueueOutput("queue-items", Connection = "AzureWebJobsStorage")]  
            public string[] Messages { get; set; }  
      
            public HttpResponseData HttpResponse { get; set; }  
        }  
    }  
    

    Run the Function App, hit the endpoint, and check the queue.
    159367-image.png


0 additional answers

Sort by: Most helpful