服务总线主题订阅过滤器 [英] Service bus Topic subscription filter

查看:65
本文介绍了服务总线主题订阅过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事一个将消息发布到服务总线主题的项目.我的主题有两个订阅.有没有办法过滤我的订户将收听的消息?

I am working on an project that publish message to a service bus topic. I have two subscriptions on my topic. Is there a way to filter the message that my subscriber will listen?

假设这是我的留言文字.

Assuming this is my message text.

{
"Data" : {
   "Name": "Johnny Cruz"
   "Gender": "Male"
 }
}

我只想听一条具有男性性别的消息.这是可以在Topic中配置的东西吗?

I only want to listen to a message that has a Male gender. Is this something configurable in Topic?

推荐答案

用户可以定义他们希望从某个主题接收哪些消息.您可以参考主题过滤器和操作

Subscribers can define which messages they want to receive from a topic. You could refer to Topic filters and actions.

服务总线支持三种过滤条件:

Service Bus supports three filter conditions:

  • 布尔型过滤器-TrueFilter和FalseFilter导致所有到达的消息(true)或未选择任何到达的消息(false)用于订阅.

  • Boolean filters - The TrueFilter and FalseFilter either cause all arriving messages (true) or none of the arriving messages (false) to be selected for the subscription.

SQL过滤器-SqlFilter包含类似SQL的条件表达式,该表达式在代理中根据到达消息的用户定义属性和系统属性进行评估.所有系统属性必须以sys为前缀.在条件表达式中.用于筛选条件的SQL语言子集测试属性(EXISTS)的存在以及空值(IS NULL),逻辑NOT/AND/OR,关系运算符,简单数值算术和简单文本模式匹配的存在性喜欢.

SQL Filters - A SqlFilter holds a SQL-like conditional expression that is evaluated in the broker against the arriving messages' user-defined properties and system properties. All system properties must be prefixed with sys. in the conditional expression. The SQL-language subset for filter conditions tests for the existence of properties (EXISTS), as well as for null-values (IS NULL), logical NOT/AND/OR, relational operators, simple numeric arithmetic, and simple text pattern matching with LIKE.

相关过滤器-CorrelationFilter包含一组条件,这些条件与一个或多个到达消息的用户和系统属性相匹配.通常的用途是与CorrelationId属性进行匹配,但应用程序还可以选择与ContentType,Label,MessageId,ReplyTo,ReplyToSessionId,SessionId,To和任何用户定义的属性进行匹配.当到达消息的属性值等于相关过滤器中指定的值时,存在匹配.对于字符串表达式,比较区分大小写.指定多个匹配属性时,过滤器会将它们组合为逻辑AND条件,这意味着要匹配,所有条件都必须匹配.

Correlation Filters - A CorrelationFilter holds a set of conditions that are matched against one or more of an arriving message's user and system properties. A common use is to match against the CorrelationId property, but the application can also choose to match against ContentType, Label, MessageId, ReplyTo, ReplyToSessionId, SessionId, To, and any user-defined properties. A match exists when an arriving message's value for a property is equal to the value specified in the correlation filter. For string expressions, the comparison is case-sensitive. When specifying multiple match properties, the filter combines them as a logical AND condition, meaning for the filter to match, all conditions must match.

以下是演示代码:

使用过滤器创建订阅

var filter=new SqlFilter("(sys.Label='Male');
namespaceManager.CreateSubscription(topicName, subName,filter);

示例消息

var message = new BrokeredMessage(body);
var message.Label = "Male";// or Female

这篇关于服务总线主题订阅过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆