【问题标题】:Not able to run Cosmos DB Change Feed Trigger Azure Function locally无法在本地运行 Cosmos DB 更改源触发 Azure 函数
【发布时间】:2020-08-24 13:06:32
【问题描述】:

我无法在本地运行 Cosmos DB Change Feed Trigger 功能。

Cosmos DB 更改源触发 Azure 函数:

public static class NotificationChangeFeed
    {
        [FunctionName("NotificationChangeFeed")]
        public static async Task Run([CosmosDBTrigger(
            databaseName: "FleetHubNotifications",
            collectionName: "Notification",
            ConnectionStringSetting = "CosmosDBConnection",
            CreateLeaseCollectionIfNotExists = true,
            LeaseCollectionName = "leases")]IReadOnlyList<Document> input,
            [Inject] ILoggingService loggingService,
            [Inject] IEmailProcessor emailProcessor)
        {
            var logger = new Logger(loggingService);

            try
            {
                if (input != null && input.Count > 0)
                {
                    foreach (Document document in input)
                    {
                        string requestBody = document.ToString();
                        var notification = requestBody.AsPoco<Notification>();

                        var result = await emailProcessor.HandleEmailAsync(notification, logger);

                        if (result)
                        {
                            logger.Info($"Email Notification sent successfully for file name: {document.Id}");
                        }
                        else
                        {
                            logger.Warning($"Unable to process document for Email Notification for file with name: {document.Id}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error($"Unable to process Documents for Email Notification for Files: {input?.Count}", ex,
                    nameof(NotificationChangeFeed));
                throw;
            }
        }
    }

local.settings.json

{
  "IsEncrypted": "false",
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard ": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "CosmosDbId": "FleetHubNotifications",
    //Localhost
    "CosmoDbAuthKey": "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
    "CosmoDbEndpoint": "https://localhost:8081/",
    "CosmosDBConnection": "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
}
}

当我按 F5 时,它卡在控制台窗口中。(如下图所示)

也不能调用http触发函数。调用时出现以下错误:

错误:连接 ECONNREFUSED 127.0.0.1:7071

有什么想法吗?

【问题讨论】:

    标签: c# azure azure-cosmosdb azure-cosmosdb-changefeed


    【解决方案1】:

    是的,在那部分你只能得到 http 函数的端点。其他函数也被初始化并等待任何类型的事件。哟可以看这里:找到以下函数,4个http触发,另外2个是blob触发。

    如果您想调试 NotificationChangeFeed 函数,您必须在数据库上创建一个新文档并让该函数运行并等待该事件。您将在控制台中看到遥测数据,您可以调试该功能。

    【讨论】:

    • 但我无法调用事件 http 触发函数。得到“错误:连接 ECONNREFUSED 127.0.0.1:7071”
    • 但是您正在尝试运行 NotificationChangeFeed??还是其他http函数??
    • 我正在尝试同时运行 http 触发器和 cosmos db 触发器。
    • 我不知道,我们需要更多信息。如果您有正在运行的功能并从邮递员调用此端点localhost:7071/api/AddOrUpdateEmailTemplate,那么您将得到 ECONNREFUSED??
    • 是的,正确!通过邮递员调用时,我遇到了同样的错误。
    猜你喜欢
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    • 2023-01-31
    • 2019-01-04
    • 1970-01-01
    相关资源
    最近更新 更多