gpt4 book ai didi

.net - Azure:Function App Cosmosdb触发本地开发

转载 作者:行者123 更新时间:2023-12-03 03:34:38 29 4
gpt4 key购买 nike

我目前正在开发函数应用,我想使用 CosmosDBTrigger。

这是我的规范:

  • dotnet --version > 6.0.401
  • func --version > 4.0.4736
  • CosmosDB 模拟器 > azure-cosmosdb-emulator-2.14.7-c041c584
  • Windows 10 企业版

我的问题:

 The 'blabla' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.blabla'. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create Collection Information for blabla_Container in database blabla_Database with lease leases in database blabla_Database : Unable to resolve app setting for property 'CosmosDBTriggerAttribute.ConnectionStringSetting'. Make sure the app setting exists and has a valid value. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Unable to resolve app setting for property 'CosmosDBTriggerAttribute.ConnectionStringSetting'. Make sure the app setting exists and has a valid value.

我的 Azure 函数设置

 public static async Task Run(
[CosmosDBTrigger(
databaseName: "blabla_Database",
collectionName: "blabla_Container",
ConnectionStringSetting = "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
LeaseCollectionName = "leases",
LeaseCollectionPrefix = "trigger",
CreateLeaseCollectionIfNotExists = true
)] string input,
FunctionContext executionContext
)

主机.json

    {
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
},
"logLevel": { "default": "Trace" },
"fileLoggingMode": "always"

}
}

Local.settings.json

"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"FUNCTIONS_WORKER_RUNTIME_VERSION": "~4"

运行 CosmosDBEmulator 的命令

.\Microsoft.Azure.Cosmos.Emulator.exe /Port=8081 /AllowNetworkAccess [/NoFirewall] /Key=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==

什么有效?

  • 我可以毫无问题地访问浏览器
  • 我可以从资源管理器创建数据库和容器

所以每当我启动我的函数应用程序时就会出现这个问题,并且我一直在互联网上尝试各种解决方案,但它们都不起作用......甚至检查我的 Windows 防火墙设置...目前我别无选择,并向社区请求帮助。

预先感谢您的宝贵时间。

最佳答案

ConnectionStringSetting 必须是设置的名称,而不是值。

例如:

 public static async Task Run(
[CosmosDBTrigger(
databaseName: "blabla_Database",
collectionName: "blabla_Container",
ConnectionStringSetting = "myCosmosDBConnection",
LeaseCollectionName = "leases",
LeaseCollectionPrefix = "trigger",
CreateLeaseCollectionIfNotExists = true
)] string input,
FunctionContext executionContext
)

在您的 settings.json 文件中:

{
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"FUNCTIONS_WORKER_RUNTIME_VERSION": "~4",
"myCosmosDBConnection": "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
}
}

请记住,当您部署此 Function 时,不会部署本地设置文件,您需要在 Function App 配置上设置这些配置。

还要记住,受监控的容器 (blabla_Container) 需要存在。

引用:

关于.net - Azure:Function App Cosmosdb触发本地开发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73798131/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com