c# - 具有服务总线触发器的隔离 azure 功能 - 来自 azure 应用程序配置的连接字符串

标签 c# azure azure-functions .net-6.0 azure-app-configuration

我在运行基于 .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/

相关文章:

c# - 在 Visual Studio 中使用 C# 脚本开发 Azure Function

c# - 为什么 c# 需要 "var"标识符?

c# - 在字符串中查找值

c# - 如何判断对象是否继承自抽象泛型类

c# - 如何在我的控制台应用程序中获取 Microsoft 图形结果?

azure - 如何与第三方共享 Azure Function 日志

c# - .NET - c# - 需要跨分区查询,但禁用了 DocumentDB 数据访问问题

azure - "421 Active data channel timed out.",通过 SQL 存储过程从 Azure VM 进行 FTP 客户端连接

azure - AKS 群集托管标识中的 Nginx 服务无权读取 publicIPAddresses

azure - 仅将 Azure Function 中间件用于选定的函数