Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

Azure Functions Project with input binding from DocumentDB

Open garthmason opened this issue 9 years ago • 3 comments

I've downloaded the preview tooling and VS2017 preview as described in yesterday's blog.

I was trying to recreate a function that I'd tested in the portal/csx template. It's timer triggered, so I can use the existing template to create that function, run and debug locally (that all works as expected).

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
}

The problem for me is, how do I translate my other input parameter bindings for outputQueue (a service bus queue) and incomingDocuments (a query to Azure Document DB) to attribute bindings in my Azure Function project.

My functions.json snippet from the portal looks like:


{
  "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
}

Maybe I'm just missing something obvious, but I can't find documentation to help me - thanks!

PS I've also posted this on StackOverflow

garthmason avatar May 11 '17 07:05 garthmason

Updated this with answer in StackOverflow, the following is working:

[FunctionName("TimerTriggerCSharp")]
 public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, 
TraceWriter log, 
[DocumentDB("test-db-dev", "TestingCollection", SqlQuery = "select * from c where c.doc = \"Test\"")]       IEnumerable<dynamic> incomingDocuments, 
[ServiceBus("test-output-requests", Microsoft.ServiceBus.Messaging.AccessRights.Send, Connection = "send-refresh-request",  EntityType = Microsoft.Azure.WebJobs.ServiceBus.EntityType.Queue)] ICollector<dynamic> refreshRequestQueue)

Just blocked now awaiting this fix for the ServiceBus binding.

garthmason avatar May 12 '17 03:05 garthmason

Thanks for the update!

lindydonna avatar May 15 '17 18:05 lindydonna

Helpful tip for others who run into same issue as above, nugget for DocumentDb is not part of "Microsoft.Azure.WebJobs", must add "Microsoft.Azure.WebJobs.Extensions.DocumentDB" to the project

koushik-aravalli avatar Jun 01 '17 15:06 koushik-aravalli