无法在本地运行Cosmos DB Change Feed触发Azure功能

时间:2020-08-24 13:06:32

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

我无法在本地运行Cosmos DB Change Feed触发器功能。

Cosmos DB更改Feed触发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

有什么想法吗?

enter image description here

1 个答案:

答案 0 :(得分:0)

是的,您仅获得http函数的端点。其他功能也会被初始化,并等待任何类型的事件。您可以在这里看到它:找到以下功能,其中4个http触发器,另外2个是blob触发器。

enter image description here

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