简体   繁体   中英

Azure Service Bus Property Filter

I am trying to filter the messages coming from an ASB so that the only messages with a certain property having a specific value are displayed. I am not sure if this is not possible, or if my syntax is incorrect.

Here is how I set the filter:

var ruleDescriptions = rules as RuleDescription[] ?? rules.ToArray();
var filter = new SqlFilter("PropertyName='PropertyValue'");
if (ruleDescriptions.All(x=>x.Filter != filter))
        {
            _client.AddRule("FilterName", filter);
        }

The Value in this case is a string. When I run this, I receive events with all different values for that Property.

I also tried the same thing, but with no single quotes around the PropertyValue with no success. How do I set this filter?

After further research, I realized I needed to remove the default filter with the following:

    if (ruleDescriptions.Any(ruleDescription => ruleDescription.Name == "$Default"))
        {
            _client.RemoveRule("$Default");
        }

This default rule is added when the subscription is created if no other rules are added at the same time. In this case, I am not the owner of the Topic I am subscribing to, and the subscription was created for me. Therefore the '$Default' rule was already added and picking up all messages.

After adding this, the above filter worked as expected-- only received messages based on the specified PropertyValue.

Source: http://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-topics-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