简体   繁体   中英

Setup configuration and run azure queue trigger function locally

I am trying to run an azure queue trigger function locally. I installed Azure Storage Emulator and ran the command "AzureStorageEmulator.exe init" to create "AzureStorageEmulatorDb59" database on the "(localdb)\\MSSQLLocalDB" server.

In my azure functions project which has the queue trigger function, I have a local.settings.json file. What settings should be added in that file and what exactly should be the connection string and where should I add it? My queue trigger function is mentioned below. What should be added in place of "my-queue" mentioned after "QueueTrigger" attribute? Please help me with this

  [FunctionName("TestQTFunction")]
    public static void Run([QueueTrigger("my-queue", Connection = "AzureQueueConnectionString")]string myQueueItem, ILogger log)
    {
       // Do something
    }

Update :

In local.settings.json:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

In my code:

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

"my-queue" is the name of the queue the one you want to trigger, when a message is put into the queue. So change it to the queue name which you want to trigger.

The connection string in local.settings.json should be in this format :

"AzureWebJobsStorage":"DefaultEndpointsProtocol=https;AccountName=[name];AccountKey=[key]"

also make sure right click the local.settings.json file -> property -> set "copy to output directry" to "copy if newer".

then in the Run method, change connection="AzureQueueConnectionString" to Connection = "AzureWebJobsStorage".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM