Class MqttTopicMatcher

Namespace
Kuestenlogik.Bowire.Protocol.Mqtt.Mock
Assembly
Kuestenlogik.Bowire.Protocol.Mqtt.dll

MQTT topic-pattern matcher. Supports the two wildcards the MQTT spec defines on subscriptions:

  • + — exactly one level (e.g. sensors/+/temp matches sensors/room1/temp but not sensors/a/b/temp).
  • # — zero or more trailing levels, must be the last segment (e.g. sensors/# matches sensors, sensors/a, sensors/a/b/c).

On a successful match, the positional wildcard values are returned so callers can expose them to the dynamic-value substitutor as \({topic.0}</code>, <code>\){topic.1}, …, and the # tail as ${topic.rest}.

public static class MqttTopicMatcher
Inheritance
MqttTopicMatcher
Inherited Members

Methods

IsPattern(string?)

True when the given pattern carries at least one wildcard (+ or #).

public static bool IsPattern(string? pattern)

Parameters

pattern string

Returns

bool

TryMatch(string?, string, out Dictionary<string, string>)

Test whether topic (a concrete MQTT topic) satisfies pattern (a pattern that may carry + / # wildcards), and collect the wildcard bindings.

public static bool TryMatch(string? pattern, string topic, out Dictionary<string, string> bindings)

Parameters

pattern string

Pattern from the recorded step, e.g. cmd/+/set.

topic string

Concrete topic from the incoming publish.

bindings Dictionary<string, string>

When the match succeeds, populated with (positional key → captured segment). + wildcards contribute "0"/"1"/... by position; the trailing # wildcard also contributes "rest" with the full remainder of the topic. Empty when a literal pattern matches its literal topic.

Returns

bool

true on match, false otherwise.