1

我正在尝试在我的预编译 C# CI/CD 部署项目中创建一个 CosmosDBTriggered 函数。

在此处输入图像描述

这是功能实现,它被部署而没有任何抱怨。我尝试过静态和实例方法。

在此处输入图像描述

监控/洞察工具报告没有错误,也没有调用,即使监视的集合在部署时有项目和更改。

在此处输入图像描述

该函数表示它已启用并具有 Cosmosdb 触发器:

在此处输入图像描述

我尝试单独添加这些依赖项,但没有更改:

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.10" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.2.1" />

如我所料,此函数不会出现在任何 CosmosDB 集合的触发器中,但我认为这可能是针对不同类型的触发器。

我缺少什么配置步骤?

更新

当我注释掉这个 [CosmosDB] DocumentClient 绑定(以及任何依赖它的东西)时,就会调用该函数。所以我想这是一起使用这些绑定的问题吗?

在此处输入图像描述

4

2 回答 2

1

根据您更新的帖子,问题是由于绑定中的一些配置问题,Functions 运行时没有初始化您的 Function。

通常,实际错误应该在 Application Insights 日志中。

您正在使用的 Cosmos DB 输出绑定缺少集合和数据库属性。检查官方示例:https ://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-input?tabs=csharp#http-trigger-get-multiple-docs-using -documentclient-c和假设CosmosDBConnection是一个变量,它指向包含连接字符串的设置的设置名称:

[CosmosDB(
                databaseName: "<your-db-name>",
                collectionName: "<your-collection-name>",
                ConnectionStringSetting = CosmosDBConnection)] DocumentClient dbClient,
于 2021-05-04T01:32:33.730 回答
1

你确定你在 azure 上设置了CosmosDbConnectionin azure function app 吗?

例如,这是我的函数应用程序:

Function1.cs

using System;
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp109
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([CosmosDBTrigger(
            databaseName: "testbowman",
            collectionName: "testbowman",
            ConnectionStringSetting = "str",
            CreateLeaseCollectionIfNotExists = true,
            LeaseCollectionName = "lease")]IReadOnlyList<Document> input, ILogger log)
        {
            if (input != null && input.Count > 0)
            {
                log.LogInformation("Documents modified " + input.Count);
                log.LogInformation("First document Id " + input[0].Id);
            }
        }
    }
}

local.settings.json

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "str": "AccountEndpoint=https://testbowman.documents.azure.com:443/;AccountKey=xxxxxx;"
  }
}

但是在将函数应用部署到azure时,不会使用local.settings.json,需要在此处设置连接字符串:

在此处输入图像描述

azure 上的功能应用程序不会告诉你这件事,它只是不起作用。

于 2021-05-03T02:26:34.687 回答