我已经在Azure中创建了服务总线,主题和对该主题的订阅。我有一个逻辑应用程序,当消息到达时会触发该逻辑应用程序,但是我需要对该订阅应用一个过滤器(或规则?),以便在逻辑应用程序处理该消息之前,它在消息头中查找特定值。我在逻辑应用程序或Azure门户中看不到要为订阅创建筛选器的任何地方。有什么机制可以为订阅创建过滤器?
答案 0 :(得分:0)
您是如何创建主题订阅的?您是否使用过ARM模板?
在创建订阅时,可以将SqlFilter添加到主题订阅中应用的规则。
下面的ARM模板(taken from here)向您展示了如何向主题订阅中的规则添加SqlFilter
"resources": [{
"apiVersion": "[variables('sbVersion')]",
"name": "[parameters('serviceBusNamespaceName')]",
"type": "Microsoft.ServiceBus/Namespaces",
"location": "[variables('location')]",
"sku": {
"name": "Standard",
},
"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('serviceBusSubscriptionName')]",
"type": "Subscriptions",
"dependsOn": [
"[parameters('serviceBusTopicName')]"
],
"properties": {},
"resources": [{
"apiVersion": "[variables('sbVersion')]",
"name": "[parameters('serviceBusRuleName')]",
"type": "Rules",
"dependsOn": [
"[parameters('serviceBusSubscriptionName')]"
],
"properties": {
"filterType": "SqlFilter",
"sqlFilter": {
"sqlExpression": "StoreName = 'Store1'",
"requiresPreprocessing": "false"
},
"action": {
"sqlExpression": "set FilterTag = 'true'"
}
}
}]
}]
}]
}]
您需要在rules子资源的properties成员中使用类似Sql的表达式添加过滤器
例如
"sqlExpression": "YourMessageProperty='YourExpectedValue'",
如果不使用ARM模板,则Service Bus Explorer允许您删除默认的订阅规则,并使用自己的SqlFilter创建一个新的订阅规则。
HTH