Skip to content

Commit 0812f20

Browse files
jbertramtabish121
authored andcommitted
ARTEMIS-5826 improve filter doc
1 parent 062e5a2 commit 0812f20

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

artemis-selector/src/test/java/org/apache/activemq/artemis/selector/SelectorTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,20 @@ public void testJMSPropertySelectors() throws Exception {
104104

105105
@Test
106106
public void testDottedProperty() throws Exception {
107-
MockMessage message = createMessage();
108-
message.setJMSType("selector-test");
109-
message.setStringProperty("a.test", "value");
110-
message.setJMSMessageID("id:test:1:1:1:1");
107+
testQuotedProperty('.');
108+
}
111109

112-
assertSelector(message, "\"a.test\" = 'value'", true);
110+
@Test
111+
public void testHyphenatedProperty() throws Exception {
112+
testQuotedProperty('-');
113+
}
114+
115+
private void testQuotedProperty(char c) throws Exception {
116+
final String value = "value";
117+
final String key = "a" + c + "test";
118+
MockMessage message = createMessage();
119+
message.setStringProperty(key, value);
120+
assertSelector(message, "\"" + key + "\" = '" + value + "'", true);
113121
}
114122

115123
@Test

docs/user-manual/filter-expressions.adoc

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,31 @@ The value is an integer.
5757

5858
Any other identifiers used in core filter expressions will be assumed to be properties of the message.
5959

60-
The JMS and Jakarta Messaging specs state that a String property should not get converted to a numeric when used in a selector.
61-
So for example, if a message has the `age` property set to `String` `21` then the following selector should not match it: `age > 18`.
62-
STOMP clients, for example, can only send messages with string properties, which is a bit limiting.
63-
Therefore, if you want your filter expressions to auto-convert `String` properties to the appropriate number type, just prefix it with `convert_string_expressions:`.
64-
If you changed the filter expression in the previous example to be `convert_string_expressions:age > 18`, then it would match the aforementioned message.
60+
== Property Identifier Constraints
6561

66-
The JMS and Jakarta Messaging specs also state that property identifiers (and therefore the identifiers which are valid for use in a filter expression) are an:
62+
The JMS and Jakarta Messaging specs state that property identifiers (and therefore the identifiers which are valid for use in a filter expression) are an:
6763

6864
____
6965
unlimited-length sequence of letters and digits, the first of which must be a letter.
70-
A letter is any character for which the method `Character.isJavaLetter` returns `true`.
66+
A letter is any character for which the method https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Character.html#isJavaLetter(char)[`Character.isJavaLetter`] returns `true`.
7167
This includes `_` and `$`.
72-
A letter or digit is any character for which the method `Character.isJavaLetterOrDigit` returns `true`.
68+
A letter or digit is any character for which the method https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Character.html#isJavaLetterOrDigit(char)[`Character.isJavaLetterOrDigit`] returns `true`.
7369
____
7470

75-
This constraint means that hyphens (i.e. `-`) cannot be used.
76-
However, this constraint can be overcome by using the `hyphenated_props:` prefix.
77-
For example, if a message had the `foo-bar` property set to `0` then the filter expression `hyphenated_props:foo-bar = 0` would match it.
71+
=== Working Around These Constraints
72+
73+
These constraints mean that characters like `.` (dot) and `-` (hyphen) cannot be used within property identifiers.
74+
However, if you want to work around these constraints, you can surround the identifier with quotation marks in the filter expression.
75+
For example, if a message had a property named `foo-bar` set to `0` then the filter expression `"foo-bar" = 0` would match it, whereas `foo-bar = 0` would *not* match.
76+
77+
== Property Value Conversion
78+
79+
The JMS and Jakarta Messaging specs also state that a `String` property should not get converted to a numeric value when used in a selector.
80+
So for example, if a message has the `age` property set to the `String` "21" then the following selector should not match it: `age > 18`.
81+
82+
However, some protocols (e.g. STOMP) can only send messages with `String` properties, which is a bit limiting.
83+
Therefore, if you want your filter expressions to auto-convert `String` properties to the appropriate number type, just prefix it with `convert_string_expressions:`.
84+
If you changed the filter expression in the previous example to be `convert_string_expressions:age > 18`, then it would match the aforementioned message.
7885

7986
== XPath
8087

0 commit comments

Comments
 (0)