简体   繁体   中英

ARM template : Multiple rules(filters) with in an subscription

Hi I am working on creating service bus, topics, subscription and filters using ARM template. I have created all but the issue I am facing is in creating multiple filter with in an subscription. here is the snippet from template that I am using

      "copy": {
        "name": "subscriptions-outer-loop",
        "count": "[length(parameters('topics'))]"
        },
        "name": "[concat(parameters('serviceBus').name,'-subscriptions')]",
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2019-10-01",
        "properties": {
            "mode": "Incremental",
            "expressionEvaluationOptions": {
                "scope": "inner"
            },
            "parameters": {
                "serviceBus": {
                    "value": "[parameters('serviceBus').name]"
                },
                "currentTopic": {
                    "value": "[parameters('topics')[copyIndex()]]"
                }
              },
            "template": {
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                    "serviceBus": { "type": "string" },
                    "currentTopic": { "type": "object" }
                },
                "resources": [
                    {
                        "copy": {
                            "name": "subscriptions-inner-loop",
                            "count": "[length(parameters('currentTopic').subscriptions)]"
                        },
                        "name": "[concat(
                                parameters('serviceBus'),'/',
                                parameters('currentTopic').name, '/',
                                parameters('currentTopic').subscriptions[copyIndex()].name)]",
                        "type": "Microsoft.ServiceBus/namespaces/topics/subscriptions",
                        "apiVersion": "2017-04-01",
                        "properties": {
                          "forwardTo":"[parameters('currentTopic').subscriptions[copyIndex()].queueName]"
                        },
                        "resources": [
                          {
                            
                            "apiVersion": "2017-04-01",
                            "name": "[concat(parameters('currentTopic').subscriptions[copyIndex()].name,'1234')]",
                            "type": "Rules",
                            "dependsOn": [
                              "[resourceId('Microsoft.ServiceBus/namespaces/topics/subscriptions',
                                          parameters('serviceBus'), 
                                          parameters('currentTopic').name, parameters('currentTopic').subscriptions[copyIndex()].name)]"
                            ],
                            "properties": {
                                "filterType": "CorrelationFilter",
                                "correlationFilter": {
                                  "correlationId":"[parameters('currentTopic').subscriptions[copyIndex()].filter]" 
                              }
                            }
                          }
                        ]
                    }
                ]
            }
      },
        "dependsOn": [ "topics-loop" ]
    },

It is able to crate single filter, but I am not able to manage it for the multiple filters.

below is how my parameter file looks like:

            "value": [
                {
                    "name": "ka-integration",
                    "subscriptions": [
                        {
                            "name":"email_notify",
                            "queueName":"notification",
                            "filter":["email_notification"]
                        },
                        {
                            "name":"onboard-organization",
                            "queueName":"onboard-organization",
                            "filter":["onboard_organization"]

                        },
                        {
                            "name":"sync-user",
                            "queueName":"sync-user",
                            "filter":["sync_user"]

                        },
                        {
                            "name":"master-data",
                            "queueName":"sync-master-data",
                            "filter":["sync_master_data"]
                        },
                        {
                            "name":"onboard_user",
                            "queueName":"onboard-user",
                            "filter":["user_onboard","onboard-organization"]

                        }  
                                           
                    ]
                }
            ]
        }

In working stage above filter is string, but as I want it multiple I have changed this to an array, but not able to implement loop.

Any help or path suggestion are welcome.

Thanks

@robo98 You need to add multiple properties of type Microsoft.ServiceBus/namespaces/topics/subscriptions/rules for the same subscription.

In the below example I have define two rules for the same subscription 'mysubscriptionname' for the topic 'mytopicname'.

The filter1 if of type SqlFilter type and filter2 is of type CorrelationFilter. Similarly, you can define n number of filters just by defining properties of type Microsoft.ServiceBus/namespaces/topics/subscriptions/rules

{
   "type":"Microsoft.ServiceBus/namespaces/topics/subscriptions/rules",
   "apiVersion":"2021-06-01-preview",
   "name":"[concat(parameters('namespaces_name'), '/mytopicname/mysubscriptionname/filter1')]",
   "location":"UK West",
   "dependsOn":[
      "[resourceId('Microsoft.ServiceBus/namespaces/topics/subscriptions', parameters('namespaces_name'), 'mytopicname', 'mysubscriptionname')]",
      "[resourceId('Microsoft.ServiceBus/namespaces/topics', parameters('namespaces_name'), 'mytopicname')]",
      "[resourceId('Microsoft.ServiceBus/namespaces', parameters('namespaces_name'))]"
   ],
   "properties":{mysubscriptionname
      "action":{
         
      },
      "filterType":"SqlFilter",
      "sqlFilter":{
         "sqlExpression":"1=1",
         "compatibilityLevel":20
      }
   }
},
{
   "type":"Microsoft.ServiceBus/namespaces/topics/subscriptions/rules",
   "apiVersion":"2021-06-01-preview",
   "name":"[concat(parameters('namespaces_name'), '/mytopicname/mysubscriptionname/filter2')]",
   "location":"UK West",
   "dependsOn":[
      "[resourceId('Microsoft.ServiceBus/namespaces/topics/subscriptions', parameters('namespaces_name'), 'mytopicname', 'mysubscriptionname')]",
      "[resourceId('Microsoft.ServiceBus/namespaces/topics', parameters('namespaces_name'), 'mytopicname')]",
      "[resourceId('Microsoft.ServiceBus/namespaces', parameters('namespaces_name'))]"
   ],
   "properties":{
      "action":{
         
      },
      "filterType":"CorrelationFilter",
      "correlationFilter":{
         "correlationId":"mycorrelationId",
         "label":"mylabelname",
         "properties":{
            
         }
      }
   }
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM