gpt4 book ai didi

azure - 如何使用 Azure 应用程序配置将 Azure Function 配置为使用动态配置?

转载 作者:行者123 更新时间:2023-12-03 03:29:59 24 4
gpt4 key购买 nike

我正在尝试编写一个作为 Multi-Tenancy 运行的 Azure 函数。当 clientId 作为参数来自客户端时,我需要使用标签从 Azure 应用程序配置获取其配置。

让我用伪代码来解释一下;

我正在使用 .Net 6 Azure 函数隔离。我在 Program.cs 中进行了配置,如下面的代码所示;

new HostBuilder()
.ConfigureAppConfiguration(builder =>
{
string cs = "connection-string"; //which is actually comes from environment veriable
builder.AddAzureAppConfiguration(options =>
{
options.Connect(cs);
//options.Select(KeyFilter.Any, Environment.GetEnvironmentVariable("ClientId")); //It works that way, but I don't want to do it. I need to read the clientId while I receive the request
});
})

假设我们制作了一个中间件并且发出了一个请求

public RequestMiddleware(){
//Here I need to inject some service
}

//Invoke method of middleware
public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next){
HttpRequestData requestData = await context.GetHttpRequestDataAsync();
requestData.Headers.TryGetValues("client-id", out var clientId);
var id = clientId.First();
//And here, I need to configure App Configuration to use the id as a label. As I did in the Program.cs
//like this ; options.Select(KeyFilter.Any, id);
}

是否可以在请求生命周期中通过标签加载配置?请记住,标准层中的 Azure 应用程序配置对请求有限制,即每小时 3000 个。这就是为什么每次都加载 AppConfiguration 不是一个好主意的原因。

最佳答案

您可以做的是使用静态字典来“缓存”,每当带有新客户端 ID 的请求到达时,您就获取配置并将其添加到字典中以供将来的请求。

关于azure - 如何使用 Azure 应用程序配置将 Azure Function 配置为使用动态配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74890504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com