I've been able to figure out how to setup an Azure ARM Template that creates/manages an Azure Service Bus Namespace, Topic and Subscription to receive all messages. However, the Microsoft documentation is extremely lacking still on ARM Tempates, and I am unable to figure out how to define a SqlFilter for the Subscription within the template that you can manage using the .NET SDK.
Does anyone know how to add a Sql Filter to a Service Bus Topic Subscription within an ARM Template?
Here's a link to the ARM Template I have for creating the Service Bus Topic and Subscription without Sql filter:
Also, here's the source of the ARM Template I'm referring to:
{
"$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": {
}
}
Currently, ARM Templates do not support creating/managing Azure Service Bus Topic Subscription Filters.
Use the Service Bus Explorer app. If you already know what SQL filter that you want to create, I suggest you to download and use this application. Download it from here
This is how you Add Rules to a subscription:
This is how you view the Rules that you've created:
It's pretty simple to use the Service Bus Explorer app. Since it's user interactive, you can always configure your service bus then go to Azure Portal to retrieve the ARM template.
A Sql Filter should be inside a Rule, so we should create a rule within the Service Bus Topic Subscription. For example:
I have tried to deploy this template, but I get the following error:
From the error message, "'The template resource cannot reference itself", I am guessing that creating Sql Filter for a Topic Subscription is not yet implemented in ARM template.
After some more diggings, I believe that Topic Subscription Rule is not manageable by Resource Manager yet. Here is the things I tried.
I use this PowerShell script to create a Topic Subscription with a rule. I have done some modification to the script by adding a name to the rule,
$RuleDescription.Name = "rule1"
.The Topic Subscription is successfully created, and I can use the following PowerShell command to get the Topic Subscription.
When I try to get the Topic Subscription Rule with a similar PowerShell command:
I get the following error:
However, if I use
$NamespaceManager.GetRules($TopicPath,$Name)
, I do get the above rule successfully. That means the rule is created successfully.Just add following into your subscription resource to create SQL Filter and Action:
,"resources": [{ "apiVersion": "[variables('sbVersion')]", "name": "$Default", "type": "Rules", "dependsOn": ["[parameters('serviceBusSubscriptionName')]"], "properties": { "filterType": "SqlFilter", "sqlFilter": { "sqlExpression": "1=1", "requiresPreprocessing": false }, "action": { "sqlExpression": "set something = 'something'" } } }]
The Subscription syntax to add a Sql filter has changed recently.
You can find the latest examples in this ARM template:
https://github.com/Azure/azure-quickstart-templates/blob/master/201-servicebus-create-topic-subscription-rule/azuredeploy.json
This is now possible as per the following quick start template which illustrates adding a SQL Filter :
https://github.com/Azure/azure-quickstart-templates/blob/master/201-servicebus-create-topic-subscription-rule/azuredeploy.json
Also if you are looking to add a Correlation Filter via ARM, I've been able to do so by setting the
Rules
resource as follows: