gpt4 book ai didi

c# - 带有 CosmosDBTrigger 的 Azure 函数似乎不是由 upsert 触发的

转载 作者:行者123 更新时间:2023-12-02 07:07:55 25 4
gpt4 key购买 nike

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

[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

我已将其从 Visual Studio 发布到 Azure,并且可以看到该函数是使用以下 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;.

我运行该函数,然后将文档添加到集合中,但日志一直显示在过去的 n 分钟内没有新的跟踪并且我期望看到的应用程序事件没有被执行写的。

我在这个设置中错过了什么吗?

最佳答案

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

leaseCollection 用于协调 Function App 的多个实例(工作线程),以在工作线程之间分配分区。

即使对于监听 Cosmos DB 更改源的单个函数来说,它也是必需的。

关于c# - 带有 CosmosDBTrigger 的 Azure 函数似乎不是由 upsert 触发的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52115599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com