.NET 8 V4 Azure Function隔离模式CosmosDB连接异常求助
Azure Functions隔离模式(.NET 8 V4)部署后无法连接CosmosDB排查求助
搭建了基于.NET 8 V4版本的Azure Functions隔离模式应用,通过CosmosDB触发器与绑定实现对CosmosDB的数据读写操作。本地环境下,通过local.settings.json配置连接字符串后应用运行正常,但部署到Azure平台后,函数虽能启动运行,却无法与CosmosDB建立通信。已在Azure门户中通过环境变量和连接字符串选项配置对应信息,问题仍未解决,以下是相关代码与配置信息,恳请协助排查:
代码片段
public CosmosDBFunction(ILogger<CosmosDBFunction> logger, IHttpClientFactory httpClientFactory) { _httpClientFactory = httpClientFactory.CreateClient(); _logger = logger; _cosmosClient = new CosmosClient("AccountEndpoint=<Connection>"); } [Function(nameof(Function))] public static async Task<string> RunOrchestrator( [OrchestrationTrigger] TaskOrchestrationContext context) { ILogger logger = context.CreateReplaySafeLogger(nameof(CosmosDBFunction)); logger.LogInformation("----Function Started-----"); string pagesToLinks = await context.CallActivityAsync<string>(nameof(somefunction)); string linksToClins = await context.CallActivityAsync<string>(nameof(somefunction)); string Blinks = await context.CallActivityAsync<string>(nameof(somefunction)); logger.LogInformation("----Function Finished-----"); return "Operation Is Completed"; } [Function(nameof(SomeFunction))] [CosmosDBOutput(databaseName: "X", containerName: "Y", Connection = "ConnectionNameSavedInLocal.Setting.json" , CreateIfNotExists = true, PartitionKey = "/dd")] public async Task<string> ScanLinksAndInsertIntoLinksContainer ([ActivityTrigger] string name, [CosmosDBInput( databaseName:"ss", containerName:"pt", Connection = "ConnectionNameSavedInLocal.Setting.json" )] List<todo> todos, FunctionContext executionContext){}
Host.json配置
{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" }, "enableLiveMetricsFilters": true }, "extensions": { "cosmosDB": { "connectionMode": "Direct", "userAgentSuffix": "MyDesiredUserAgentStamp" } } } }
local.settings.json配置
{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated", "CosmosConnection": "AccountEndpoint=https: <ConnectionString>" } }
Azure门户连接字符串配置
[ { "name": "CosmosConnection", "value": "AccountEndpoint= <ConnectionString>", "type": "DocDb", "slotSetting": false } ]
内容的提问来源于stack exchange,提问作者redar ismail
相关产品推荐
相关产品推荐

