Skip to main content

TOPIC_MATCH Operator

AMPS provides the TOPIC_MATCH operator to compare a string value against a topic pattern using the topic matching policy configured for the instance. This operator is useful when a message field contains a topic name, routing key, subject, or destination and you want to evaluate that field using the same topic matching rules that AMPS uses for subscriptions and topic-based configuration.

The syntax of the operator is:

string_expression TOPIC_MATCH pattern_literal

AMPS also supports the negated form:

string_expression NOT TOPIC_MATCH pattern_literal

The right side of the predicate must be a literal string. As with LIKE, you can use a standard quoted string or a raw string literal when that makes the expression easier to read.

Relationship to LIKE

LIKE and TOPIC_MATCH both compare strings to patterns, but they are intended for different jobs:

PredicatePattern Semantics
LIKEAlways uses PCRE syntax, regardless of the configured topic matching policy.
TOPIC_MATCHUses the configured topic matching policy.

Use LIKE when you need full regular expression matching on string values. Use TOPIC_MATCH when the string you are matching should be interpreted as a topic or subject according to the AMPS topic matching policy.

Policy-Specific Behavior

The behavior of TOPIC_MATCH depends on the instance TopicMatchingPolicy.

PolicyBehavior
pcreInterprets the pattern literal as a PCRE pattern.
solaceInterprets the pattern literal using Solace topic wildcard syntax. Solace is a registered trademark of Solace Corporation.
tibcoInterprets the pattern literal using TIBCO topic wildcard syntax for TIBCO Rendezvous and TIBCO Enterprise Message Service (EMS). TIBCO is a trademark or registered trademark of Cloud Software Group, Inc.
mqttInterprets the pattern literal using MQTT topic wildcard syntax. MQTT is a trademark of OASIS Open.

When topic pattern matching is disabled by setting RegexTopicSupport to false without setting TopicMatchingPolicy, TOPIC_MATCH behaves like an exact string comparison.

Under the solace, tibco, and mqtt policies, PCRE-only constructs such as ^, $, and .* are not valid topic patterns.

Examples

When TopicMatchingPolicy is pcre, TOPIC_MATCH uses PCRE:

/destination TOPIC_MATCH '^orders/(na|eu)/.*$'

When TopicMatchingPolicy is solace, TOPIC_MATCH uses Solace wildcard rules:

/destination TOPIC_MATCH 'orders/*/priority>'

When TopicMatchingPolicy is tibco, TOPIC_MATCH uses TIBCO subject matching rules with . as the topic level separator:

/subject TOPIC_MATCH 'ORDERS.*.PRIORITY.>'

When TopicMatchingPolicy is mqtt, TOPIC_MATCH uses MQTT wildcard rules:

/topic TOPIC_MATCH 'sensors/+/temperature'

The negated form returns true when the value does not match the topic pattern:

/topic NOT TOPIC_MATCH 'sensors/+/temperature'

Arrays

TOPIC_MATCH is array-aware, just like LIKE and the other boolean comparison operators.

When the value on the left side is an array, TOPIC_MATCH returns true if any element in the array matches the pattern. NOT TOPIC_MATCH returns true only when no element in the array matches the pattern.