下面是个人理解,如果有不正确的地方麻烦指出来.更正.
JMS 消息选择器 配置
1. 消息选择器是根据 header 和 properties 允许客户端选择性的制定需要接收的消息
注意 消息选择器是无法利用 消息主题(Body)进行过滤的. 无论你的消息主题是什么类型. 文本.或者对象,或者键值对
根据消息选择器定义的条件,如果为true ,例如 消息头或者属性值 为某个标识符 ,这个时候表示接收消息.
否则 ,如果选择器为空 则为不过滤消息.默认接收所有该通道的消息.该消息过滤类似SQL语句.不过还是要准从一定的约束
消息过滤才起作用. 例如: 过滤 usercode 不等于 admin的消息. 应该这样定义: usercode<>'admin', 而不能写
usercode!='admin' , 毕竟他没有sql这样强大的容错功能.
2. 消息过滤字串默认是不区分大小写的.并且过滤条件的优先级是按照从左至右的顺序, 不过你可以利用 ()
来改变消息的优先级
比如: 我要接收 usercode 不等于 admin 或者 接收 当usercode是admin的时候并且receiver等于you的 消息
我们可以这样定义 selector = usercode<>'admin' or (usercode='admin' and receiver='you')
3.下面我们就消息选择器的规范和可定义范围说明下
- 可接收类型:
- 字符串 , 利用单引号包含字符串表示条件值
- 整形, 是不包含小数点的正整数或者负整数
- 浮点型, 正浮点型或者负浮点型 比如: -98.0232 或者 4.234 等
- 布尔常量 TURE 或者 FALSE . 注意 如果用字符串表示 是不区分大小写的. 比如: isDestroy = true
- 属性标识符定义:
- 其实说白了就跟java 定义变量名一样.字母开头. 或者 _ $ 等等
- 不能用 NULL , TRUE FALSE 等定义. 这些就不多说了
- 不能用
NOT,AND,OR,BETWEEN,LIKE,IN,IS,或者 ESCAPE定义 - 要么在heads中定义 要么在 property中定义. 如果双方约束是利用properties中定义. 但是接收没有,它不会自定去头引用中查找. 直接会是空
- 根据属性定义的类型去相应的取值 , 例如这里将 2 当做字符串放入了属性体重.就应该这样取
myMessage.setStringProperty("NumberOfOrders", "2");如果这样取的话.就会报异常. 我就发愁 , 应该不会有人这样搞吧"NumberOfOrders > 1"
- 属性标识符是区分大小写的 .(这个是区分的)
- 任何以 JMSX 开头的 都是属性定义
- 任何以
JMS_ 开头的都是provider-specific 属性名称 -
任何不以JMS 开头的 属性定义 都是一个application-specific 属性名称
- 空格,换行等. 相应参考java 属性定义
- 表达式:
- 可以是条件表达式
- 可以是算术表达式
- 可以是比较运算和逻辑运算组成的表达式
- 支持 () 左右括号
- 支持逻辑运算的优先顺序表达式 例如:
NOT,AND,OR - 比较运算符有:
=,>,>=,<,<=,<>(not equal)- 根据类型相应的利用运算符比较
- 字符串和布尔比较 只支持 = 或者 <>
- 算术运算符的优先顺序:
-
+,-(unary) -
*,/(multiplication and division) -
+,-(addition and subtraction) - 算术运算必须遵循java 语言规范
-
- 算术表达式
arithmetic-expr1(不)介于arithmetic-expr2 和arithmetic-expr3之间 例如:arithmetic-expr1 [NOT] BETWEEN arithmetic-expr2 AND arithmetic-expr3
-
"age BETWEEN 15 AND 19"is equivalent to"age >= 15 AND age <= 19" -
"age NOT BETWEEN 15 AND 19"is equivalent to"age < 15 OR age > 19"
-
-
标识符 [NOT] IN (string-literal1 , string-literal2 ,...)(比较字符串或者 null 是否在其中存在)-
"Country IN (' UK', 'US', 'France') "is true for'UK'and false for'Peru'; 相当于"(Country = ' UK') OR (Country = ' US') OR (Country = ' France') " -
"Country NOT IN (' UK', 'US', 'France') "is false for'UK'and true for'Peru'; 相当于"NOT ((Country = ' UK') OR (Country = ' US') OR (Country = ' France')) " - If identifier of an
INorNOT INoperation isNULL, the value of the operation is unknown.
-
-
identifier [NOT] LIKE pattern-value [ESCAPE escape-character ](comparison operator, whereidentifierhas aStringvalue;pattern-valueis a string literal where'_'stands for any single character;'%'stands for any sequence of characters, including the empty sequence; and all other characters stand for themselves. The optionalescape-characteris a single-character string literal whose character is used to escape the special meaning of the'_'and'%'inpattern-value.)-
"phone LIKE '12%3'"is true for'123'or'12993'and false for'1234' -
"word LIKE 'l_se'"is true for'lose'and false for'loose' -
"underscored LIKE '\_%' ESCAPE '\'"is true for'_foo'and false for'bar' -
"phone NOT LIKE '12%3'"is false for'123'or'12993'and true for'1234' - If
identifierof aLIKEorNOT LIKEoperation isNULL, the value of the operation is unknown.
-
-
标识符是null-
"prop_name IS NULL"
-
-
标识符非空 not null-
"prop_name IS NOT NULL"
-
-
JMS providers are required to verify the syntactic correctness of a message selector at the time it is presented. A method that provides a syntactically incorrect selector must result in a
JMSException. JMS providers may also optionally provide some semantic checking at the time the selector is presented. Not all semantic checking can be performed at the time a message selector is presented, because property types are not known.The following message selector selects messages with a message type of car and color of blue and weight greater than 2500 pounds:
"JMSType = 'car' AND color = 'blue' AND weight > 2500"
Null Values
As noted above, property values may be
NULL. The evaluation of selector expressions containingNULLvalues is defined by SQL92NULLsemantics. A brief description of these semantics is provided here.SQL treats a
NULLvalue as unknown. Comparison or arithmetic with an unknown value always yields an unknown value.The
IS NULLandIS NOT NULLoperators convert an unknown value into the respectiveTRUEandFALSEvalues.布尔操作符使用三值逻辑,由下表定义: T表示TRUE F表示FALSE U表示UNDEFINE
AND 运算符对应结果图
| AND | T | F | U +------+-------+-------+------- | T | T | F | U | F | F | F | F | U | U | F | U +------+-------+-------+-------
OR 运算符对应结果图
| OR | T | F | U +------+-------+-------+-------- | T | T | T | T | F | T | F | U | U | T | U | U +------+-------+-------+-------
NOT运算结果:
| NOT +------+------ | T | F | F | T | U | U +------+-------
本文介绍JMS消息选择器的工作原理及使用规范,包括如何通过消息头部和属性筛选特定消息、支持的数据类型、表达式语法及特殊操作符。
1576

被折叠的 条评论
为什么被折叠?



