c# - 无法在本地运行 Cosmos DB 更改源触发 Azure 函数
问题描述
我无法在本地运行 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
有什么想法吗?
解决方案
推荐阅读
- python - 检测图像上的斑点,对检测到的斑点进行 3D 绘图,然后计算 PYTHON
- java - 返回 ArrayList 时,我是否必须返回
和它一起? - javascript - 将自定义 CSS 添加到 Vuetify 组件的问题
- algorithm - 贪心算法是否可能也是动态规划算法?
- unity3d - 为什么场景视图分辨率高但游戏视图分辨率低(以像素为单位)
- python-3.x - 使用熊猫的 groupby 和 for 循环
- angular - angular 5调用函数绑定类将导致函数被无限次调用
- string - 如何删除 awk 中的空格和换行符以进行字符串插入?
- c# - 实体框架性能问题
- amazon-sagemaker - 如何在本地环境中部署 AWS SageMaker 线性学习者模型