我是第一次使用 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;
.
我运行该函数,然后将文档添加到集合中,但日志只是一直显示No new trace in the past n min(s)
并且我期望看到的应用程序事件没有被写入。
我在这个设置中错过了什么吗?