2

I am creating a simple queue triggered azure function using Visual Studio. I am connecting it with my storage account, but for some reason its not working. Any help is appreciated.

This is my code: (auto-generated by VS)

[FunctionName("QueueTest")]
public static void Run([QueueTrigger("my-queue", Connection = "")]string myQueueItem, TraceWriter log)        
{            
    log.Info($"C# Queue trigger function processed: {myQueueItem}");
}

This is my local.settings.json

{
"IsEncrypted": false,  
  "Values":{

  "AzureWebJobsStorage":"DefaultEndpointsProtocol=https;AccountName=accountname;AccountKey=accountkey"
  }
}
ArslanIqbal
  • 569
  • 1
  • 6
  • 19

3 Answers3

2

Queue trigger by default use a AzureWebJobsStorage account. All you need to do is just remove Connection parameter from the attribute:

[FunctionName("QueueTest")]
public static void Run([QueueTrigger("my-queue")]string myQueueItem, TraceWriter log)        
{            
    log.Info($"C# Queue trigger function processed: {myQueueItem}");
}

Ideally if you are a Windows user, use Azure Storage Emulator to connect to local queues. Afterwards change the connection string in your local.settings.json file:

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

If you are not a Windows user, you must connect to queues hosted on the Azure platform. To do this, find the storage account linked to your functions and copy the connection string from his settings (Storage Account -> Access Keys -> Connection string)

Pawel Maga
  • 5,428
  • 3
  • 38
  • 62
  • Yes I am a windows user. I tried using Storage Emulator but was facing issue. Figured why not just try using the actual storage just to see how it works but stuck on this since then. And I tried removing the connection parameter, still not working – ArslanIqbal Oct 22 '18 at 09:27
  • It should work, it's everything what you need to set up. Check if you add a message to the correct queue in the correct storage account. Alternatively, create the http/timer/manual function, which connects to this queue using the output binding [Queue], add the message to the queue and check what will happen – Pawel Maga Oct 22 '18 at 09:33
  • I have used the same queue and same account when creating function on azure portal. For that function, it works fine. But for some reason, this function is not being bind to the queue. – ArslanIqbal Oct 22 '18 at 10:05
2

So I figured out the issue. All the configurations were fine. The issue was, Azure Function Version of my function app was 1 but for some reason, probably because of latest SDK/WebJobs, version 1 was not working correctly. So I had to create another function app with AzureFunctionVersion 2 and all worked fine.

ArslanIqbal
  • 569
  • 1
  • 6
  • 19
1

You need to add the connection string of your queue storage account to the local.settings.json and then supply the name of the connection string as the Connection parameter of the QueueTrigger, e.g. in local.settings.json

"Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=accountname;AccountKey=accountkey",
    "MyStorage": "DefaultEndpointsProtocol=https;AccountName=accountname2;AccountKey=accountkey2;EndpointSuffix=core.windows.net"
}

and in your code

[QueueTrigger("my-queue", Connection = "MyStorage")]string myQueueItem
MarkXA
  • 4,294
  • 20
  • 22