使用Azure应用程序配置设置Dotnet隔离的ServiceBusTrigger连接字符串

xqkwcwgp  于 2023-04-22  发布在  其他
关注(0)|答案(1)|浏览(89)

我刚刚从进程项目中的dotnet切换到隔离项目,但现在我在ServiceBusTrigger中配置连接字符串时遇到问题。
Program.cs

var host = new HostBuilder()
    .ConfigureAppConfiguration(builder =>
        builder
            .AddAzureAppConfiguration(options =>
            {
                options.Connect(Environment.GetEnvironmentVariable(CommonConfigurationConstants.AppConfigurationConnectionString))
                    .Select(KeyFilter.Any, LabelFilter.Null)
                    .Select(KeyFilter.Any, ConfigurationConstants.AppLabel)
                    .ConfigureKeyVault(kv =>
                    {
                        kv.SetCredential(new DefaultAzureCredential());
                    })
                    .ConfigureRefresh(refreshOptions =>
                        refreshOptions.Register(CommonConfigurationConstants.SentinelKey, refreshAll: true))
                        .UseFeatureFlags();
            })
            .AddJsonFile("local.settings.json", true))
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(s =>
    {
        s.ConfigureMediatR()
            .ConfigureAutomapper()
            .ConfigureFluentValidations()
            .ConfigureServices()
            .ConfigureRepositories()
            .ConfigureDatabase();
        s.AddFeatureManagement();
    })
    .Build();

host.Run();

SampleFunction.cs

public class SampleFunction
    {
        [Function("SampleFunction")]
        public async Task Run(
            [ServiceBusTrigger(
                "sampleTopic",
                "sampleSubscription",
                Connection = "QueueConnectionString",
                IsSessionsEnabled = true)]
            BaseQueueRequest req, string messageId)
        {
               ...
        }
    }

我将QueueConnectionString添加到我的Azure应用程序配置中,但如果我不将其放置在local.settings.json中,应用程序仍然无法启动。问题是-是否有方法在Azure应用程序配置中设置此连接字符串?

8fsztsew

8fsztsew1#

隔离的Azure Functions不支持从中间件解析表达式。这在https://github.com/Azure/AppConfiguration/issues/203中进行了跟踪。

相关问题