gpt4 book ai didi

azure - 如何从 ServiceBusAttribute 构造函数内部访问环境变量?

转载 作者:行者123 更新时间:2023-12-03 04:56:25 25 4
gpt4 key购买 nike

我有一个绑定(bind)到服务总线的 azure 函数,我像这样使用它:

[FunctionName("MyFunctionName")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[ServiceBus("myqueueortopicname", Connection = "ServiceBusConnection")] IAsyncCollector<string> messages)

我正在尝试使服务总线队列名称可配置并取自Environment.GetEnvironmentVariable("MyMessageBusQueueName")

[ServiceBus(Environment.GetEnvironmentVariable("MyMessageBusQueueName"), Connection = "ServiceBusConnection")] IAsyncCollector<string> messages)`

local.Settings.json:

{
"IsEncrypted": false,
"Values": {
"MyMessageBusQueueName": "myqueueortopicname",
"ServiceBusConnection": "..."
},
"ConnectionStrings": {}
}

但是我遇到了一个错误:

An attribute argument must be a constant expression, typeof expressionor array

最佳答案

您需要通过用 % 包装环境变量名称来使用绑定(bind)表达式。将队列名称定义为 %MyMessageBusQueueName% ,它将绑定(bind)到环境变量

[ServiceBus("%MyMessageBusQueueName%", Connection = "ServiceBusConnection")] IAsyncCollector<string> messages)

阅读 Microsoft 文档中有关绑定(bind)表达式的信息 --- here .

关于azure - 如何从 ServiceBusAttribute 构造函数内部访问环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68610035/

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