A client only receive the messages that meet the filtering condition specified in the message selector. A message selector filters the messages received in the destination to only receive those that meet the specified condition. It compares the properties specified in a message and the condition specified in the message selector. Only the properties can be compared but not the values of the body which stores the main contents.
The syntax of a message selector complies with a part of the SQL92 expression. A message selector is evaluated in the order of left to right. The order can be changed using parenthesis. It consists of literals, identifiers, and expressions.
Literal
String enclosed in single quotes. (for example, 'cat')
Numeric string stored as long or double. (for example, 50, 1.414)
Identifier
Property name. The type of the literal after the property must match the property type. If they are not matched, the property will be evaluated to false. If the property does not exist in a message, the result of the evaluation is null.
A literal or expression cannot be used as an identifier. It is case sensitive.
Reserved properties cannot be used as an identifier. For more information about the reserved properties, refer to "1.3.4. Messages".
Keywords used in a message selector cannot be used as an identifier.
Expression
The following comparison, logical, and mathematical operators can be used to specify a conditional expression.
Classification | Description |
---|---|
Comparison Operator | =, >, >=, <, <=, <> |
Logical Operator | NOT, AND, OR |
Mathematical Operator | +, - (unary operator), *, /, +, - (The priority order is +, - (unary operator) > *, / > +, and -.) |
Conditional expression
Expression1 [NOT] BETWEEN Expression2 AND Expression3
"weight BETWEEN 50 AND 70" is the same as "weight >= 50 AND weight <= 70".
"weight NOT BETWEEN 50 AND 70" is the same as "weight < 50 OR weight > 70".
Identifier [NOT] IN (Literal1, Literal2, …)
"type IN ('cat', 'tiger', 'puma')" is the same as "type = 'cat' OR type = 'tiger' OR type = 'puma'".
"type NOT IN (20, 30, 40)" is the same as "type <> 20 AND type <> 30 AND type <> 40".
Identifier [NOT] LIKE Pattern
A question mark (?) and asterisk (*) can be used to specify a pattern. A single must exist in the place of a question mark (?) to be true. 0 or more characters can exist in the place of an asterisk (*).
In "year LIKE '200?' ", '2009' is true but '200' or '20001' is false.
In "year LIKE '200*' ", the strings that begin with '200' are true.
The following is an example of using a message selector.
"Type = 'cat' AND Weight BETWEEN 5 AND 15"
If both Type = 'cat' and Weight BETWEEN 5 AND 15 ("weight >= 5 and weight <= 15") are true, the above statement is true.