使用 IAsyncCollector 时如何从配置中获取服务总线主题?
How can I get the service bus topic from configuration when using IAsyncCollector?
我有一个 Azure 函数,它向服务总线发布一些消息,声明如下:
[FunctionName(FunctionNames.PublishMessages)]
public async Task PublishMessages(
[ActivityTrigger] IEnumerable<Foo> messages,
[ServiceBus("TopicName", Connection = "ServiceBusConnectionString")] IAsyncCollector<string> collector,
ILogger log)
{
foreach (var message in messages)
{
await collector.AddAsync(JsonSerializer.Serialize(message));
}
await collector.FlushAsync();
}
服务总线的输出绑定采用主题的名称和值包含连接字符串的配置键的名称。
我不想在方法签名中对主题进行硬编码,而是希望从函数的配置中获取它,就像获取连接字符串一样。这可能吗?非常感谢任何帮助。
您可以通过 referencing it using %
完成。所以
[ServiceBus("%TopicNameSetting%", Connection = ...
并使用密钥 TopicNameSetting
创建应用设置
我有一个 Azure 函数,它向服务总线发布一些消息,声明如下:
[FunctionName(FunctionNames.PublishMessages)]
public async Task PublishMessages(
[ActivityTrigger] IEnumerable<Foo> messages,
[ServiceBus("TopicName", Connection = "ServiceBusConnectionString")] IAsyncCollector<string> collector,
ILogger log)
{
foreach (var message in messages)
{
await collector.AddAsync(JsonSerializer.Serialize(message));
}
await collector.FlushAsync();
}
服务总线的输出绑定采用主题的名称和值包含连接字符串的配置键的名称。
我不想在方法签名中对主题进行硬编码,而是希望从函数的配置中获取它,就像获取连接字符串一样。这可能吗?非常感谢任何帮助。
您可以通过 referencing it using %
完成。所以
[ServiceBus("%TopicNameSetting%", Connection = ...
并使用密钥 TopicNameSetting