This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bindings": [ | |
{ | |
"type": "cosmosDBTrigger", | |
"name": "input", | |
"direction": "in", | |
"leaseCollectionName": "leases", | |
"connectionStringSetting": "<your-connectionstring-setting>", | |
"databaseName": "<your-monitored-database>", | |
"collectionName": "<your-monitored-collection>", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bindings": [ | |
{ | |
"type": "cosmosDBTrigger", | |
"name": "input", | |
"direction": "in", | |
"leaseCollectionName": "leases", | |
"connectionStringSetting": "<your-connectionstring-setting>", | |
"databaseName": "<your-monitored-database>", | |
"collectionName": "<your-monitored-collection>", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("Trigger1")] | |
public static void Run( | |
[CosmosDBTrigger("<your-monitored-database>", | |
"<your-monitored-collection>", | |
ConnectionStringSetting = "<your-connectionstring-setting>" | |
LeaseCollectionPrefix = "trigger1")] | |
IReadOnlyList<Document> input, | |
TraceWriter log) | |
{ | |
log.Info("Documents modified " + input.Count); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"documentDB": { | |
"connectionMode": "Direct", | |
"protocol": "Tcp" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cosmosDB": { | |
"connectionMode": "Direct", | |
"protocol": "Tcp" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static HttpResponseMessage Run( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "HttpInputBindingByIdInRoute/{id}")] HttpRequestMessage req, | |
[CosmosDB(databaseName: "%CosmosDBDatabase%", | |
collectionName: "%CosmosDBCollection%", | |
ConnectionStringSetting = "CosmosDBConnectionString", | |
UseMultipleWriteLocations = true, | |
PreferredLocations = "Central US,North Central US" | |
Id = "{id}")] Document document, | |
ILogger log) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<HttpResponseMessage> Run( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, | |
[CosmosDB(databaseName: "%CosmosDBDatabase%", | |
collectionName: "%CosmosDBCollection%", | |
ConnectionStringSetting = "CosmosDBConnectionString", | |
UseMultipleWriteLocations = true, | |
PreferredLocations = "Central US" | |
)] IAsyncCollector<MyClass> documentsToSave, | |
ILogger log) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "2.0", | |
"logging": { | |
"fileLoggingMode": "always", | |
"logLevel": { | |
"Host.Triggers.CosmosDB": "Trace" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("Monitor")] | |
public static async Task Monitor( | |
[TimerTrigger("*/1 * * * * *", RunOnStartup = true)] TimerInfo timer, // Timer will trigger every 1 second, adjust CRON expression | |
[CosmosDB("%MonitoredDatabase%", "%MonitoredCollection%", ConnectionStringSetting = "CosmosDB")] DocumentClient monitoredCollectionClient, | |
[CosmosDB("%MonitoredDatabase%", "leases", ConnectionStringSetting = "CosmosDB")] DocumentClient leaseCollectionClient, | |
ILogger log) | |
{ | |
var estimator = GetRemainingWorkEstimator(monitoredCollectionClient, leaseCollectionClient); | |
var remainingWork = await estimator.GetEstimatedRemainingWork(); | |
// Send custom metric to App Insight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Lazy<IRemainingWorkEstimator> remainingWorkEstimator; | |
public static IRemainingWorkEstimator GetRemainingWorkEstimator( | |
DocumentClient monitoredCollectionClient, | |
DocumentClient leaseCollectionClient) | |
{ | |
if (remainingWorkEstimator == null) | |
{ | |
// Pull the Connection string from the environment, Environment.GetEnvironmentVariable will read the local.settings.json file or the deployed Function App configuration | |
CosmosDBConnectionString cosmosDBConnectionString = new CosmosDBConnectionString(Environment.GetEnvironmentVariable("CosmosDB")); |