TsgcWSPServer_sgc › Properties › UseMatchesMask

UseMatchesMask Property

Enables mask-style matching of channel names instead of an exact string match.

Syntax

property UseMatchesMask: Boolean read FUseMatchesMask write FUseMatchesMask;

Default Value

False

Remarks

UseMatchesMask is a runtime-only property, it is not published in the Object Inspector, so it can only be set in code. It is public, not published.

By default a channel argument (in Subscribe, Broadcast, Publish, ...) is matched against a connection's subscriptions with an exact string comparison. When UseMatchesMask is True, the server instead expands the channel argument as a Delphi mask (System.Masks.MatchesMask: * and ? wildcards, plus character sets such as [abc]) against the set of channel names that currently have at least one live subscriber. If the mask does not match any live channel, the argument is used as a literal channel name.

UseMatchesMask is not MQTT topic-filter matching. # and + have no special meaning, and * matches across / like any other character, there is no path-segment concept. For MQTT-compliant wildcards use TsgcWSPClient_MQTT / TsgcWSPServer_MQTT instead.

This option is most useful on the publish side, to fan a message out to every channel currently matching a pattern:

oProtocol.Broadcast('payload', 'topic1/*');

It is of limited use on the subscribe side: a client that sends Subscribe('topic1/*') before any concrete topic1/... channel has a subscriber is simply subscribed to the literal channel name topic1/*, since there is nothing yet for the mask to expand against.

Example

// server side, enable mask matching for this protocol instance
sgcWSPServer_sgc1.UseMatchesMask := True;

// clients subscribe to concrete channel names
// sgcWSPClient_sgc1.Subscribe('topic1/a');
// sgcWSPClient_sgc2.Subscribe('topic1/b');

// publish once, delivered to every live channel matching the mask
sgcWSPServer_sgc1.Broadcast('payload', 'topic1/*');

Back to Properties