gpt4 book ai didi

azure - 二头肌 : Creating multiple topics with multiple subscriptions

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

我是 bicep 新手,一直在努力实现 Bicep 脚本来部署具有许多主题和订阅的 Azure 服务总线。

我添加的每个主题都有可变数量的订阅(例如,通知主题可能有 3 个订阅,但分析主题可能有 2 个订阅)。

有没有办法可以循环遍历并创建所有主题资源,然后循环遍历所有订阅并将它们添加到正确的主题定义中?

最佳答案

这有点取决于我们在这里讨论的主题数量。如果你只是创建一个小数字,那么我会做这样的事情;

TopicsAndSubs.bicep

@description('Name of the Service Bus namespace')
param serviceBusNamespaceName string

@description('Name of the Topic')
param serviceBusTopicName string = 'theweather'

param topicSubscriptions int = 3

resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2022-10-01-preview' existing = {
name: serviceBusNamespaceName
}

resource serviceBusTopic 'Microsoft.ServiceBus/namespaces/topics@2022-10-01-preview' = {
parent: serviceBusNamespace
name: serviceBusTopicName
properties: {

}

resource sub 'subscriptions' = [for i in range(0,topicSubscriptions): {
name: 'sub-${i}'
properties: {}
}]
}

<小时/>

但是,如果它变得更加古怪,那么您将需要使用模块(一个单独的主题文件和一个用于订阅的文件)。像这样的东西;

主题.bicep

@description('Name of the Service Bus namespace')
param serviceBusNamespaceName string

@description('Name of the Topic')
param topicsAndSubscriptions array = [
{
name: 'notification'
subscriptions: [
'none'
'ntwo'
'nthree'
'nfour'
]
}
{
name: 'analysis'
subscriptions: [
'aone'
'atwo'
'athree'
'afour'
]
}
]

resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2022-10-01-preview' existing = {
name: serviceBusNamespaceName
}

resource serviceBusTopic 'Microsoft.ServiceBus/namespaces/topics@2022-10-01-preview' = [ for topic in topicsAndSubscriptions: {
parent: serviceBusNamespace
name: topic.name
properties: {

}
}]

module subs 'sub.bicep' = [ for topic in topicsAndSubscriptions: {
name: '${topic.name}-subs'
params: {
servicebusNamespaceName: serviceBusNamespaceName
topicName: topic.name
subscriptions: topic.subscriptions
}
}]

订阅.bicep

param servicebusNamespaceName string
param topicName string
param subscriptions array = ['asubscription','anotherone']

resource sub 'Microsoft.ServiceBus/namespaces/topics/subscriptions@2022-10-01-preview' = [for i in subscriptions: {
name: '${servicebusNamespaceName}/${topicName}/${i}'
properties: {}
}]

关于azure - 二头肌 : Creating multiple topics with multiple subscriptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76516806/

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