Dotnet Isolated ServiceBusTrigger 连接字符串设置与 Azure App Configuration

huangapple go评论61阅读模式
英文:

Dotnet Isolated ServiceBusTrigger connection string setup with Azure App Configuration

问题

I've just switched from dotnet in-process project to an isolated one, but now I have a problem with configuring the connection string in my 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)
    {
        // ...
    }
}

I added QueueConnectionString to my Azure App Configuration, but still, if I don't place it in local.settings.json, the application does not start. The question is - is there a way to set up this connection string in Azure App Configuration?

英文:

I've just switched from dotnet in proccess project to isolated one, but now I have problem with configuring connection string in my 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)
        {
               ...
        }
    } 

I added QueueConnectionString to my Azure App Configuration, but still, if I'll not place it in local.settings.json application does not start.
Question is - is there a way to setup this connection string in Azure App Configuration?

答案1

得分: 0

中间件的表达式解析在独立的Azure Functions中不受支持。这在https://github.com/Azure/AppConfiguration/issues/203中有记录。

英文:

The expression resolution from middleware is not supported in isolated Azure Functions. This is tracked in https://github.com/Azure/AppConfiguration/issues/203.

huangapple
  • 本文由 发表于 2023年4月17日 18:09:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76034002.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定