Azure function queue trigger. Possible bug binding configuration in connection string?

Viewed 658

I have an azure function in dotnet 5 with a queue trigger

    public static class DequeuePendingJournal
{
    [Function("DequeuePendingJournal")]
    public static void Run([QueueTrigger("%JournalQueueName%", Connection = "%JournalQueueConnectionString%")] string queueItem,
        FunctionContext context)
    {
        var logger = context.GetLogger("DequeuePendingJournal");
        logger.LogInformation($"C# Queue trigger function processed: {queueItem}");
    }
}

Note the values in %%.

In my local settings I have both key (JournalQueueConnectionString and JournalQueueName) with values XXXXXXXXXX. I also have "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated".

When I run the Azure function it seems the binding is not working fine because I have the next error:

The 'DequeuePendingJournal' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.DequeuePendingJournal'. Microsoft.Azure.WebJobs.Extensions.Storage: Storage account connection string 'AzureWebJobsXXXXXXXXXXXXXX' does not exist. Make sure that it is a defined App Setting.

It seems, for some reason, the framework is adding 'AzureWebJobs' as a prefix, no idea why.

How can I fix this?

3 Answers

In QueueTrigger attribute, the Connection attribute is to specify the name of app setting name that contains the storage account connection string to use. So instead of defining it as Connection = "%JournalQueueConnectionString%", define it as Connection = "JournalQueueConnectionString" if your app setting name is JournalQueueConnectionString (so no wrapping with %).

Note - syntax "%JournalQueueName%" is correct to look for a app setting name for queue name.

public static void Run([QueueTrigger("%JournalQueueName%", Connection = "JournalQueueConnectionString")] string queueItem,
        FunctionContext context)
{
   ........ your code here
}

It seems, for some reason, the framework is adding 'AzureWebJobs' as a prefix, no idea why.

It's not adding any prefix when it's looking for the connection string key, but it surely has a bug when displaying the error messages. By design, if your connection string key starts with 'AzureWebJobs', for example, if it's 'AzureWebJobsMyStorage', you can just use 'MyStorage' as the queue trigger function's Connection attribute. (Mentioned here under Connections -> Connection string)

But when the connection string is faulty (as in your case because it has %...%), Microsoft forgot their own convention and went about prefixing any erroneous key with 'AzureWebJobs' before throwing out the error messages :)

An Azure Function always expects (and needs) an AzureWebJobsStorage connection string.

AzureWebJobsStorage

The Azure Functions runtime uses this storage account connection string for normal operation. Some uses of this storage account include key management, timer trigger management, and Event Hubs checkpoints. The storage account must be a general-purpose one that supports blobs, queues, and tables.

and

When creating a function app, you must create or link to a general-purpose Azure Storage account that supports Blob, Queue, and Table storage. This is because Functions relies on Azure Storage for operations such as managing triggers and logging function executions.

Running locally, having it set to UseDevelopmentStorage=true should suffice. This enables the Function App to run against emulators like the Storage emulator, or the new Azurite emulator.

Related