Package org.mockserver.async.subscribe
Class MqttTopicFilter
java.lang.Object
org.mockserver.async.subscribe.MqttTopicFilter
Matching of concrete MQTT topic names against MQTT topic filters, per
MQTT 3.1.1 §4.7 (the same wildcard semantics apply to MQTT 5).
A subscription may use wildcards, but a message always arrives on a concrete topic. Recorded messages are therefore stored under the concrete topic, while verification asks for the filter the user subscribed with — so the two must be reconciled by filter matching rather than by string equality.
Wildcards
+— single-level wildcard; matches exactly one topic level and must occupy an entire level (sport/+/score).#— multi-level wildcard; must be the last level of the filter and matches that level and all levels beneath it. Because#includes the parent level,sport/#matchessportas well assport/tennis/player1.
Reserved topics
Per §4.7.2 a leading wildcard does not match a topic beginning with$
(e.g. $SYS/...), so # does not match $SYS/broker/uptime
while $SYS/# does.-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsWildcard(String filter) static booleanisValidFilter(String filter) static booleanMatch a concrete topic name against a topic filter.
-
Method Details
-
containsWildcard
- Returns:
- true if the given topic filter contains an MQTT wildcard character, and so cannot be compared to a concrete topic by equality alone.
-
isValidFilter
- Returns:
- true if the filter is well formed:
+occupies a whole level and#occupies a whole level and appears only as the final level.
-
matches
Match a concrete topic name against a topic filter.- Parameters:
filter- the (possibly wildcarded) topic filter subscribed withtopic- the concrete topic a message arrived on- Returns:
- true if the filter selects the topic
-