Search code examples
azureazure-functionsazure-function-appazure-queuesazure-storage-queues

Azure function with .net core 3.1 not triggering from Queue storage


I am trying to trigger an Azure function when a new queue message is added. Both the storage account and the azure function are in the same region.

For my Azure Function, I clicked on Add, Azure Queue Storage Trigger, I gave my function a name, and the Queue name is the same name as my queue. I tried adding a new queue message, nothing is triggered.

I then tried modifying the code as the following:

using System;

[FunctionName("QueueTrigger")]
[StorageAccount("storagetestaccount1")]

public static void Run(
    [QueueTrigger("queue1")] string myQueueItem, 
    ILogger log)
{
    log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
}

But still no success. Any idea what might be causing this?

This is my first azure function so not sure what's correct and what's not.


Solution

  • I think the correct code is this:

        public static class Function1
        {
            [FunctionName("Function1")]
            public static void Run([QueueTrigger("queueName", Connection = "connectString")]string myQueueItem, ILogger log)
            {
                log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
            }
        }
    

    Note

    If you develop locally, you should config your azure storage connect string in local.settings.json

    enter image description here

    If you develop in azure portal, you need to config connect string in Application settings:

    enter image description here