我在运行基于 .net 6 的 azure 函数(孤立的一个)时遇到一些问题。我想从 azure 应用程序配置获取到服务总线的连接字符串。 所有其他设置均已成功获取并使用 IOptions 模式提供: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-6.0 通过连接字符串到服务总线,当我尝试在本地运行该函数时,出现以下错误:
Microsoft.Azure.WebJobs.Extensions.ServiceBus: Service Bus account connection string 'AzureServiceBus' does not exist. Make sure that it is a defined App Setting.
该函数如下所示:
using Api.Contracts.BusMessage;
namespace Api.Functions.Queues;
public class Test
{
private const string FunctionName = "func";
private readonly ILogger<Test> _logger;
public Test(ILogger<Test> logger)
{
_logger = logger;
}
[Function(FunctionName)]
public async Task Run(
[ServiceBusTrigger("func", Connection = "AzureServiceBus")]
BusMessage<string> message)
{
_logger.LogInformation("Processing queue trigger message {@Message}", message);
}
}
是否可以从 Azure 应用程序配置获取连接字符串?
最佳答案
服务总线连接must come from Function App's own App Settings 。可以在 Function App 的应用程序设置中引用 Azure 应用程序配置中的值。请参阅this guide 。如果您在函数运行时从 Azure 应用程序配置中提取设置,则该设置将不可用于服务总线连接。
关于c# - 具有服务总线触发器的隔离 azure 功能 - 来自 azure 应用程序配置的连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74020791/