CosmosDBTrigger的Azure函数似乎不是由upserts触发的 [英] Azure function with CosmosDBTrigger doesn't seem to be triggered by upserts

查看:69
本文介绍了CosmosDBTrigger的Azure函数似乎不是由upserts触发的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用Azure Functions.我试图编写一个简单的函数来响应更改或添加到CosmosDb集合的文档.我编写的函数如下所示:

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() }
            });
    }
}

据我了解,当多个功能指向同一个CosmosDb时,有必要收集租约,但是在我的情况下这无关紧要.这就是为什么我将租赁集合设置为null.

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.

我已将其从Visual Studio发布到Azure,可以看到该函数是使用以下function.json创建的:

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

我还添加了一个名为CosmosDBConnection的应用程序设置,其值为AccountEndpoint=https://my-cosmosdb.documents.azure.com:443;AccountKey=myAccountKey;.

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

我运行该函数,然后将一个文档添加到集合中,但是日志仅显示No new trace in the past n min(s),并且我期望看到的应用程序事件未编写.

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?

推荐答案

我不确定这是问题的根本原因,但是您对leaseCollection的理解是错误的.

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

leaseCollection用于协调Function App的多个实例(工作人员)以在工作人员之间分配分区.

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

即使是单个函数,也需要侦听Cosmos DB更改供稿.

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

这篇关于CosmosDBTrigger的Azure函数似乎不是由upserts触发的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆