TsgcWSPClient_MQTT › Methods › UnSubscribe
Removes one or more active topic subscriptions from the current MQTT session.
function UnSubscribe(const aTopic: string; aUnsubscribeProperties: TsgcWSMQTTUnsubscribe_Properties = nil) : Word;
| Name | Type | Description |
|---|---|---|
aTopic | const string | Exact topic filter, matching a previous Subscribe call, to remove. |
aUnsubscribeProperties | TsgcWSMQTTUnsubscribe_Properties | Optional MQTT 5.0 properties (for example User Properties). Pass nil when not required. |
Packet identifier assigned to the UNSUBSCRIBE packet; correlate it with OnMQTTUnSubscribe to read the broker's reason codes. (Word)
Single-topic overload. The filter must match the one originally passed to Subscribe, including wildcards, otherwise the broker will report a "No subscription existed" reason code. Pending messages already in flight may still be delivered after the call.
MQTT.UnSubscribe('sensors/+/temperature');
function UnSubscribe(aTopics: TsgcWSTopics): Word;
| Name | Type | Description |
|---|---|---|
aTopics | TsgcWSTopics | Collection of topic filters to drop with a single UNSUBSCRIBE packet. |
Packet identifier of the batched UNSUBSCRIBE packet. (Word)
Batch overload useful when logging off a client that tracks many filters, or when a mode change forces rewiring of several subscriptions at once. Each entry in the collection produces its own reason code in the broker's UNSUBACK, reported through OnMQTTUnSubscribe.
oTopics := TsgcWSTopics.Create;
try
oTopics.Add('sensors/#');
oTopics.Add('alerts/#');
MQTT.UnSubscribe(oTopics);
finally
oTopics.Free;
end;