Skip to content

Commit 99cf2bd

Browse files
authored
[ServiceBus] update samples, docs and tests for sql rule filter (Azure#18042)
Closing issue: Azure#17525
1 parent 4c6112b commit 99cf2bd

File tree

7 files changed

+278
-219
lines changed

7 files changed

+278
-219
lines changed

sdk/servicebus/azure-servicebus/azure/servicebus/management/_models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,20 @@ class SqlRuleFilter(object):
10621062
"""Represents a filter which is a composition of an expression and an action
10631063
that is executed in the pub/sub pipeline.
10641064
1065+
.. admonition:: Example:
1066+
1067+
.. code-block:: python
1068+
:caption: Create SqlRuleFilter.
1069+
1070+
sql_filter = SqlRuleFilter("property1 = 'value'")
1071+
sql_filter_parametrized = SqlRuleFilter(
1072+
"property1 = @param1 AND property2 = @param2",
1073+
parameters={
1074+
"@param1": "value",
1075+
"@param2" : 1
1076+
}
1077+
)
1078+
10651079
:param sql_expression: The SQL expression. e.g. MyProperty='ABC'
10661080
:type sql_expression: str
10671081
:param parameters: Sets the value of the sql expression parameters if any.

sdk/servicebus/azure-servicebus/samples/async_samples/mgmt_rule_async.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
Example to show managing rule entities under a ServiceBus Subscription, including
1010
- Create a rule
11+
- Create a rule with sql filter
1112
- Get rule properties.
1213
- Update a rule
1314
- Delete a rule
@@ -19,12 +20,14 @@
1920
import os
2021
import asyncio
2122
import uuid
23+
from azure.servicebus.management import SqlRuleFilter
2224
from azure.servicebus.aio.management import ServiceBusAdministrationClient
2325

2426
CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR']
2527
TOPIC_NAME = os.environ['SERVICE_BUS_TOPIC_NAME']
2628
SUBSCRIPTION_NAME = os.environ['SERVICE_BUS_SUBSCRIPTION_NAME']
2729
RULE_NAME = "sb_mgmt_rule" + str(uuid.uuid4())
30+
RULE_WITH_SQL_FILTER_NAME = "sb_mgmt_sql_filter_rule" + str(uuid.uuid4())[:16]
2831

2932

3033
async def create_rule(servicebus_mgmt_client):
@@ -33,11 +36,25 @@ async def create_rule(servicebus_mgmt_client):
3336
print("Rule {} is created.".format(RULE_NAME))
3437
print("")
3538

39+
print("-- Create Rule with SQL Filter")
40+
sql_filter_parametrized = SqlRuleFilter(
41+
"property1 = @param1 AND property2 = @param2",
42+
parameters={
43+
"@param1": "value",
44+
"@param2" : 1
45+
}
46+
)
47+
await servicebus_mgmt_client.create_rule(TOPIC_NAME, SUBSCRIPTION_NAME, RULE_WITH_SQL_FILTER_NAME, filter=sql_filter_parametrized)
48+
print("Rule {} is created.".format(RULE_WITH_SQL_FILTER_NAME))
49+
print("")
50+
3651

3752
async def delete_rule(servicebus_mgmt_client):
3853
print("-- Delete Rule")
3954
await servicebus_mgmt_client.delete_rule(TOPIC_NAME, SUBSCRIPTION_NAME, RULE_NAME)
4055
print("Rule {} is deleted.".format(RULE_NAME))
56+
await servicebus_mgmt_client.delete_rule(TOPIC_NAME, SUBSCRIPTION_NAME, RULE_WITH_SQL_FILTER_NAME)
57+
print("Rule {} is deleted.".format(RULE_WITH_SQL_FILTER_NAME))
4158
print("")
4259

4360

sdk/servicebus/azure-servicebus/samples/sync_samples/mgmt_rule.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
Example to show managing rule entities under a ServiceBus Subscription, including
1010
- Create a rule
11+
- Create a rule with sql filter
1112
- Get rule properties and runtime information
1213
- Update a rule
1314
- Delete a rule
@@ -18,13 +19,16 @@
1819

1920
import os
2021
import uuid
21-
from azure.servicebus.management import ServiceBusAdministrationClient
22+
from azure.servicebus.management import (
23+
ServiceBusAdministrationClient,
24+
SqlRuleFilter
25+
)
2226

2327
CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR']
2428
TOPIC_NAME = os.environ['SERVICE_BUS_TOPIC_NAME']
2529
SUBSCRIPTION_NAME = os.environ['SERVICE_BUS_SUBSCRIPTION_NAME']
2630
RULE_NAME = "sb_mgmt_rule" + str(uuid.uuid4())
27-
31+
RULE_WITH_SQL_FILTER_NAME = "sb_mgmt_sql_filter_rule" + str(uuid.uuid4())[:16]
2832

2933

3034
def create_rule(servicebus_mgmt_client):
@@ -33,11 +37,25 @@ def create_rule(servicebus_mgmt_client):
3337
print("Rule {} is created.".format(RULE_NAME))
3438
print("")
3539

40+
print("-- Create Rule with SQL Filter")
41+
sql_filter_parametrized = SqlRuleFilter(
42+
"property1 = @param1 AND property2 = @param2",
43+
parameters={
44+
"@param1": "value",
45+
"@param2" : 1
46+
}
47+
)
48+
servicebus_mgmt_client.create_rule(TOPIC_NAME, SUBSCRIPTION_NAME, RULE_WITH_SQL_FILTER_NAME, filter=sql_filter_parametrized)
49+
print("Rule {} is created.".format(RULE_WITH_SQL_FILTER_NAME))
50+
print("")
51+
3652

3753
def delete_rule(servicebus_mgmt_client):
3854
print("-- Delete Rule")
3955
servicebus_mgmt_client.delete_rule(TOPIC_NAME, SUBSCRIPTION_NAME, RULE_NAME)
4056
print("Rule {} is deleted.".format(RULE_NAME))
57+
servicebus_mgmt_client.delete_rule(TOPIC_NAME, SUBSCRIPTION_NAME, RULE_WITH_SQL_FILTER_NAME)
58+
print("Rule {} is deleted.".format(RULE_WITH_SQL_FILTER_NAME))
4159
print("")
4260

4361

0 commit comments

Comments
 (0)