0

how to implement an azure function using visual code on a mac that communicates with a queue?

All the examples I come across (shown below) seem to show visual studio together with nuget package manager. What's the equivalent to download the necessary package in visual code to communicate with queues? I've downloaded the following for visual code but I get an error

https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurestorage

Code sample

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace Company.Function
{
    public static class HttpTriggerCSharp
    {      
        [FunctionName("QueueTriggerMetadata")]
        public static void Run([QueueTrigger("101functionsqueue", Connection = "AzureWebJobsStorage")]string myQueueItem, TraceWriter log)
        {
            log.Info($"C# Queue trigger function processed: {myQueueItem}");
        }
    }
}

error message when deploying

The type or namespace name 'QueueTriggerAttribute' could not be found (are you missing a using directive or an assembly reference?)

error message received after updating the csproj file

Missing value for AzureWebJobsStorage in local.settings.json. This is required for all triggers other than httptrigger, kafkatrigger. You can run 'func azure functionapp fetch-app-settings ' or specify a connection string in local.settings.json.

James
  • 697
  • 4
  • 19
  • 24

1 Answers1

1

According to my test, my function was triggered successfully after install the extension "Azure Storage for Visual Studio Code". So could you please recreate the function again after install the extension or click the "extension" button in your VS code, check if you have installed the extension successfully and check if it is enable(shown as screenshot below) enter image description here

Apart from this, you also need to check if the extension exists in your "csproj" file. In my test, if I remove

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.4" />

from the "csporj" file, it will show the error message which is same to yours'. enter image description here

Below I post my azure function for your reference, I create the function with the default setting after install the extension and it works fine. enter image description here enter image description here

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
  • Yes the reference in the csproj was missing although I'm not seeing a different error. – James Dec 03 '19 at 11:09
  • But this is because I haven't created the queue yet in storage explorer... Let me try after creating it – James Dec 03 '19 at 11:11
  • I've created the queue using my azure account within storage explorer but I'm not sure how to tell the code? – James Dec 03 '19 at 11:14
  • 1
    Hi @James You just need to start your function code and add a message in the queue which you created. Then go to your function code in VS code, it will deal with the message and print the log. After that, go back to storage explorer, click "Refresh" button, the message you added just now will missing. By the way, when you create the queue, the queue name should be same with the name in your function code. So name should be "101functionsqueue". – Hury Shen Dec 04 '19 at 02:12