我已经能够弄清楚如何设置Azure ARM模板来创建/管理Azure服务总线命名空间,主题和订阅以接收所有消息.但是,在ARM Tempates上仍然缺少Microsoft文档,我无法弄清楚如何在模板中为使用.NET SDK管理的订阅定义sqlFilter.
有谁知道如何将sql过滤器添加到ARM模板中的服务总线主题订阅?
这是我用于创建不带sql过滤器的服务总线主题和订阅的ARM模板的链接:
另外,这里是我所指的ARM模板的来源:
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": { "serviceBusNamespaceName": { "type": "string","Metadata": { "description": "Name of the Service Bus Namespace" } },"serviceBusTopicName": { "type": "string","Metadata": { "description": "Name of the Service Bus Topic" } },"serviceBusTopicSubscriptionName": { "type": "string","Metadata": { "description": "Name of the Service Bus Topic Subscription" } } },"variables": { "sbVersion": "2015-08-01" },"resources": [ { "apiVersion": "[variables('sbVersion')]","name": "[parameters('serviceBusNamespaceName')]","type": "Microsoft.ServiceBus/namespaces","location": "[resourceGroup().location]","properties": { },"resources": [ { "apiVersion": "[variables('sbVersion')]","name": "[parameters('serviceBusTopicName')]","type": "Topics","dependsOn": [ "[concat('Microsoft.ServiceBus/namespaces/',parameters('serviceBusNamespaceName'))]" ],"properties": { "path": "[parameters('serviceBusTopicName')]" },"resources": [ { "apiVersion": "[variables('sbVersion')]","name": "[parameters('serviceBusTopicSubscriptionName')]","type": "Subscriptions","dependsOn": [ "[parameters('serviceBusTopicName')]" ],"properties": { },"resources": [ ] } ] } ] } ],"outputs": { } }
解决方法
sql Filter应位于规则内,因此我们应在Service Bus主题订阅中创建规则.例如:
"resources": [ { "apiVersion": "[variables('sbVersion')]","dependsOn": [ "[parameters('serviceBusTopicName')]" ],"properties": { },"name": "[parameters('serviceBusTopicSubscriptionRuleName')]","type": "Rules","dependsOn": [ "[parameters('serviceBusTopicSubscriptionName')]" ],"resources": [ ] } ] } ]
我试图部署此模板,但我收到以下错误:
New-AzureRmResourceGroupDeployment : InvalidTemplate: Deployment template validation Failed: 'The template resource 'Microsoft.ServiceBus/namespaces/<serviceBusNamespaceName>/Topics/<serviceBusTopicName>/Subscriptions/<serviceBusTopicSubscriptionName>' cannot reference itself. Please see http://aka.ms/arm-template-expressions/#reference for usage details.'. At line:1 char:1 + New-AzureRmResourceGroupDeployment -Name ServiceBusTest -ResourceGrou ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [New-AzureRmResourceGroupDeployment],CloudException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand
从错误消息“’模板资源无法引用自身”,我猜测在ARM模板中尚未实现为主题订阅创建sql过滤器.
在进行了一些挖掘后,我认为主题订阅规则尚不可由资源管理器管理.这是我尝试过的东西.
>我使用this PowerShell script创建一个带有规则的主题订阅.我通过在规则中添加名称$RuleDescription.Name =“rule1”对脚本进行了一些修改.
>已成功创建主题订阅,我可以使用以下PowerShell命令获取主题订阅.
Get-AzureRmResource -ResourceGroupName Default-ServiceBus-EastUS ` -ResourceType Microsoft.ServiceBus/namespaces/topics/Subscriptions ` -ResourceName <namespace>/<topic>/<subscription> ` -ApiVersion 2014-09-01
>当我尝试使用类似的PowerShell命令获取主题订阅规则时:
Get-AzureRmResource -ResourceGroupName Default-ServiceBus-EastUS ` -ResourceType Microsoft.ServiceBus/namespaces/topics/Subscriptions/Rules ` -ResourceName <namespace>/<topic>/<subscription>/rule1 ` -ApiVersion 2014-09-01
我收到以下错误:
No HTTP resource was found that matches the request URI 'https://sbgm.windows.net/subscriptions/<subscriptionid>/resourceGroups/Default-ServiceBus-EastUS/providers/Microsoft.ServiceBus/namespaces/<namespace>/topics/<topic>/Subscriptions/<subscription>/Rules/rule1?api-version=2014-09-01'
>但是,如果我使用$NamespaceManager.GetRules($TopicPath,$Name),我会成功获得上述规则.这意味着该规则已成功创建.