Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 1.81 KB

File metadata and controls

50 lines (38 loc) · 1.81 KB

DotNetCore CosmosDBTrigger WebJob

Presentation

On this repository, you will have an .Net Core 2.0 WebJob using Dependency Injection and Application Insights which will listen CosmosDB data modifications.

Prerequisites

For more information about :

Steps

App Function

On https://portal.azure.com/ create a new 'Function App'. Then add a new Function based on 'CosmosDbTrigger'.

Azure Function

Go to DocumentDB settings then click on 'Add Azure Function'. Select the Collection you want to monitor, the App function you have just created and the other fields then click on 'Save'.

Code

Here is the code of the function you could use:

#r "Microsoft.Azure.Documents.Client"
using System;
using System.Collections.Generic;
using Microsoft.Azure.Documents;

public static void Run(IReadOnlyList<Document> input, ICollector<string> returnValues, TraceWriter log)
{
    var count = (input != null) ? input.Count : 0;

    log.Verbose($"There are {count} document(s).");

    for (var i = 0; i < count; i++)
    {
        log.Verbose($"input[{i}] = '{input[i]}'");
        returnValues.Add($"{input[i]}");
    }
}

It will allow you to log the data entered in the database.

Integration

In 'Integrate' section, add a new Output, select 'AzureQueueStorage' and complete the field before saving. Note: The default Queue Name is 'outqueue'. Please it like this to trigger the command in the app.

Run my code

Final step, run the App