5

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
    }
suvenk
  • 467
  • 1
  • 5
  • 24

1 Answers1

3

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".

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • Thanks for the response. To connect to the azure storage emulator, should the account key and account name values be these Account name: devstoreaccount1 Account key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw== as mentioned in the documentation here https://learn.microsoft.com/en-us/azure/storage/common/storage-use-emulator? – suvenk Jun 19 '19 at 10:12
  • @suvenk, oh, if you just want to test it locally without using real storage account, please see my updated section. – Ivan Glasenberg Jun 19 '19 at 10:31
  • Thank you so much for your detailed response. I am able to get it working and run it locally :) – suvenk Jun 20 '19 at 01:25
  • I'm getting a weird error when trying to run it locally: `The target process exited without raising a CoreCLR started event.` I tried changing the .net version, updating visual studio, but error won't change – Mario Garcia Nov 24 '21 at 11:13