2
votes

I have an Azure Function that I created in the Azure portal and now want to recreate it using the visual studio azure tooling associated with VS2017 Preview.

My function is Timer triggered, and also has an input binding for Azure DocumentDB (with a query) and an output binding to an Azure Service Bus queue.

Here's the functions.json definition from the portal:

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */5 * * * *"
    },
    {
      "type": "serviceBus",
      "name": "outputQueue",
      "queueName": "test-output-requests",
      "connection": "send-refresh-request",
      "accessRights_": "Send",
      "direction": "out"
    },
    {
      "type": "documentDB",
      "name": "incomingDocuments",
      "databaseName": "test-db-dev",
      "collectionName": "TestingCollection",
      "sqlQuery": "select * from c where c.docType = \"Test\"",
      "connection": "my-testing_DOCUMENTDB",
      "direction": "in"
    }
  ],
  "disabled": false
}

In VS2017, I create an Azure Function project, then a Azure function using the TimerTriggered template:

public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, TraceWriter log, ICollector<dynamic> outputQueue, IEnumerable<dynamic> incomingDocuments)
{
    log.Info($"C# Timer trigger function executed at: {DateTime.Now}");   

    //Inspect incomingDocuments .. push messages to outputQueue
}

Running locally, the timer is triggered as expected - but how do I recreate the input and output bindings in code? I'm not sure what attributes I should use, and what I need in json config files to wire it up.

1

1 Answers

4
votes
  1. Add reference to following nuget pacakge https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.DocumentDB/
  2. Add using Microsoft.Azure.WebJobs
  3. Update the documentDb Parameter as follows (Add other properties as well)

    [DocumentDB(ConnectionStringSetting = "")]IEnumerable<dynamic> incomingDocuments
    
  4. Update the serviceBus Parameter as follows

    [ServiceBus("test-output-requests",Connection = "ConnectionValue")]
    

Verify the generated function.json in the bin/functionName/function.json

Thanks,
Naren