简体   繁体   English

Azure Service Bus属性筛选器

[英]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. 我试图过滤来自ASB的消息,以便仅显示具有特定值的特定属性的消息。 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. 我也尝试过同样的事情,但是在PropertyValue周围没有单引号没有成功。 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. 因此,已经添加了“ $ Default”规则并提取所有消息。

After adding this, the above filter worked as expected-- only received messages based on the specified PropertyValue. 添加此内容后,上述过滤器将按预期方式工作-仅收到基于指定的PropertyValue的消息。

Source: http://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-topics-subscriptions/ 来源: http//azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-topics-subscriptions/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM