简体   繁体   English

无法在本地运行 Cosmos DB Change Feed Trigger Azure Function

[英]Not able to run Cosmos DB Change Feed Trigger Azure Function locally

I am not able to run Cosmos DB Change Feed Trigger function locally.我无法在本地运行 Cosmos DB Change Feed Trigger 功能。

Cosmos DB Change Feed Trigger Azure Function: 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本地设置.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==",
}
}

When I press F5, it got stuck in the console window.(As shown in the below screen shot)当我按 F5 时,它卡在控制台窗口中。(如下面的屏幕截图所示)

Also not able call http trigger functions.也不能调用 http 触发函数。 Getting below error while calling:调用时出现以下错误:

Error: connect ECONNREFUSED 127.0.0.1:7071错误:连接 ECONNREFUSED 127.0.0.1:7071

Any thoughts?有什么想法吗?

在此处输入图片说明

Yeah in that part you only get the endpoints of the http functions.是的,在那部分您只能获得 http 函数的端点。 The other functions are also initialized and waiting for an event of whatever type.其他函数也被初始化并等待任何类型的事件。 Yo can see it here: Found the following functions, 4 http trigger the other 2 are blob trigger.你可以在这里看到它:找到以下函数,4 个 http 触发器,另外 2 个是 blob 触发器。

在此处输入图片说明

If you want to debug your NotificationChangeFeed function you will have to create a new document on the DB and have the function runing and waiting for that event.如果要调试 NotificationChangeFeed 函数,则必须在数据库上创建一个新文档,并使该函数运行并等待该事件。 And you will see the telemetry in the console and you can debug the function.您将在控制台中看到遥测数据,您可以调试该功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM