Reputation: 31
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?
Upvotes: 1
Views: 1091
Reputation: 31
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.
Upvotes: 2