6

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
    }

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

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 learn.microsoft.com/en-us/azure/storage/common/…?
@suvenk, oh, if you just want to test it locally without using real storage account, please see my updated section.
Thank you so much for your detailed response. I am able to get it working and run it locally :)
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.