Azure function with CosmosDBTrigger doesn't seem to be triggered by upserts

a 夏天 提交于 2020-01-15 07:51:19

问题


I'm working with Azure Functions for the first time. I'm trying to write a simple function which responds to documents changed or added to a CosmosDb collection. The function I've written looks like this:

[FunctionName("ChangeLog")]
public static void Run([CosmosDBTrigger(
    databaseName: "Recaptcha",
    collectionName: "Rules",
    ConnectionStringSetting = "CosmosDBConnection",
    LeaseCollectionName = null)]IReadOnlyList<RuleConfigCollection> documents)
{
    if (documents != null && documents.Count > 0)
    {
        ApplicationEventLogger.Write(
            Diagnostics.ApplicationEvents.RecaptchaRulesChanged,
            new Dictionary<string, object>()
            {
                { "SomeEnrichment", documents[0].Rules.ToList().Count.ToString() }
            });
    }
}

By my understanding a lease collection is necessary when multiple functions are pointed at the same CosmosDb, but in my case this isn't relevant. That's why I've set the lease collection to null.

I've published this to Azure from Visual Studio and can see the function is created with the following function.json:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.12",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "connectionStringSetting": "CosmosDBConnection",
      "collectionName": "Rules",
      "databaseName": "Recaptcha",
      "leaseDatabaseName": "Recaptcha",
      "createLeaseCollectionIfNotExists": false,
      "name": "documents"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/My.Namespace.Functions.App.dll",
  "entryPoint": "My.Namespace.Functions.App.ChangeLogFunction.Run"
}

I've also added an application setting named CosmosDBConnection with the value AccountEndpoint=https://my-cosmosdb.documents.azure.com:443;AccountKey=myAccountKey;.

I run the function then add a document to the collection, but the logs just keep saying No new trace in the past n min(s) and the application events I expect to see are not being written.

Have I missed something in this setup?


回答1:


I'm not sure that's the root cause of you issue, but your understanding of leaseCollection is wrong.

leaseCollection is used to coordinate multiple instances (workers) of your Function App to distribute partitions between workers.

It is required even for a single Function listening to Cosmos DB change feed.



来源:https://stackoverflow.com/questions/52115599/azure-function-with-cosmosdbtrigger-doesnt-seem-to-be-triggered-by-upserts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!