简体   繁体   中英

Azure topic subscription filter / Subscription Rule

I have created a sample client which listens to a subscription that is attached to a Service-Bus topic. Now whenever a message is posted in that topic, its being captured by the client listening to subscriber. (as documented below)

https://github.com/Azure/azure-service-bus/tree/master/samples/DotNet/GettingStarted/Microsoft.Azure.ServiceBus/TopicSubscriptionWithRuleOperationsSample

Now I would like to add a filter/rule so that only the messages that pass certain condition defined in filter should be given to subscription.

For example, below is the message content json which is given as string,

"{"firstName": "Tony", "LastName": "Stark", "nickName": "Iron Man", "occupation":"actor"}"

How do i create a subscription rule that receives messages only for "occupation": "actor" . As per azure documentation, we need to SqlFilter however but no luck till now,

https://docs.microsoft.com/en-us/azure/service-bus-messaging/topic-filters

https://www.terraform.io/docs/providers/azurerm/r/servicebus_subscription_rule.html#example-usage-sql-filter-

We are using terraform to create resource in azure cloud. Module suggested in above link, but how to define sql_filter to consider "occupation":"actor"

filter_type = "SqlFilter" sql_filter = "???"

I have tried as below, but got invalid character ":"

sql_filter = "'occupation':'actor'"

You can't define SQL Filter on attributes in your message body as your message body could be anything. SQL Filters work on custom properties on a message.

For example, if you want to create a filter on occupation , you will need to define as one of the custom properties in your message and set it's value to actor . Then your SQL Filter expression would be like:

sql_filter = "occupation = 'actor'"

You may find this blog post useful: https://www.markheath.net/post/azure-service-bus-filtered-subscriptions .

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