MQTT Protocol

Native MQTT 3.1.1 and MQTT 5.0 client for Delphi, C++Builder and .NET. Publish-subscribe messaging over WebSocket or raw TCP with QoS 0/1/2, retained messages, last will, topic aliases and shared subscriptions.

MQTT subprotocol client

A first-class MQTT implementation that runs everywhere the Delphi / .NET runtime runs — from desktop services to mobile devices, talking to any standard-compliant MQTT broker.

Component class

TsgcWSPClient_MQTT

Standards

MQTT 3.1.1 & MQTT 5.0

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Standard / Professional / Enterprise

Full MQTT 3.1.1 & 5.0 surface

Every wire-level feature of MQTT — not just publish and subscribe.

QoS 0, 1 & 2

Fire-and-forget, at-least-once and exactly-once delivery. The QoS 2 four-way handshake (PUBLISH → PUBREC → PUBREL → PUBCOMP) is fully exposed via events for retry / audit logic.

WebSocket or raw TCP

Plug the Client property into a TsgcWebSocketClient to run MQTT over WebSockets, or use the native MQTT TCP transport on port 1883 / 8883 — same component, same API.

Retained messages

Mark publications as retained so the broker delivers the last known value to any future subscriber. Set or clear retain per-call on Publish.

Last Will & Testament

LastWillTestament registers a topic + payload the broker will publish if the client drops ungracefully — the canonical way to signal device-offline events.

Wildcard subscriptions

Topic filters with + (single level) and # (multi level) wildcards: sensors/+/temperature or devices/#.

MQTT 5 properties

Session expiry, receive maximum, maximum packet size, topic alias maximum, request response info, user properties — all accessible through ConnectProperties, PublishProperties and SubscribeProperties.

Topic aliases

MQTT 5 lets the client (and broker) replace long topic names with a 2-byte integer alias for repeat publications — huge savings for chatty telemetry streams.

Shared subscriptions

MQTT 5 $share/<group>/<topic> distributes incoming messages round-robin across a group of subscribers — the building block for horizontal worker pools.

Request / response

MQTT 5 ResponseTopic and CorrelationData properties turn pub-sub into asynchronous RPC — built into the events without extra framing.

Enhanced auth

MQTT 5 AUTH packet with AuthenticationMethod / AuthenticationData for SCRAM-style challenges — call Auth, handle OnMQTTAuth.

Keep-alive & WatchDog

HeartBeat sends PINGREQ on a tunable interval. The WatchDog reconnects automatically with exponential backoff and resumes subscriptions.

TLS via OpenSSL or SChannel

Run MQTTS on 8883 (raw TCP+TLS) or WSS on 443 with client certificates. TLSOptions.IOHandler picks OpenSSL (cross-platform) or SChannel (Windows kernel TLS).

Where MQTT shines

Lightweight framing, low overhead and stateful sessions make MQTT the default choice for these scenarios.

IoT telemetry

Sensors stream temperature, vibration, GPS and battery readings over keep-alived MQTT sessions — even on flaky LTE/Cat-M/NB-IoT links.

Connected vehicles & fleets

Bidirectional command channel with QoS 1 for fleet trackers, OBD gateways and EV charging stations — reconnect-and-resume without losing publications.

Industrial / SCADA

Replace OPC-UA polling with event-driven publish-subscribe. Topic aliases and shared subscriptions scale to thousands of PLCs and field devices.

Smart home & building

Lighting, HVAC, locks and presence sensors talking through Mosquitto or Home Assistant — the Delphi client integrates as easily as any embedded node.

Cloud IoT platforms

The same component talks to AWS IoT Core, Azure IoT Hub, Google Cloud IoT, IBM Watson, HiveMQ Cloud and EMQX — with X.509 client certificates or SAS tokens.

Web / browser dashboards

MQTT-over-WebSocket on RabbitMQ Web-MQTT (port 15675) lets the same broker push to Delphi clients and JS dashboards over a single TLS port.

Mobile push & presence

Long-lived MQTT sessions on iOS/Android with Last Will give you presence and lightweight push without a vendor-specific provider.

Microservice fan-out

Decouple producers and consumers through a central broker. Shared subscriptions round-robin work across a pool of Delphi worker services.

Works with every major MQTT broker

Spec-compliant client — verified against the brokers our customers actually deploy.

AWS IoT Core

X.509 client certificates, SigV4 over WebSocket and the AWS IoT broker quotas. See the dedicated AWS IoT page.

Azure IoT Hub

Device-SAS tokens, twin/method topics and DPS provisioning. See the Azure IoT Hub page.

HiveMQ & HiveMQ Cloud

Full MQTT 5 property surface, shared subscriptions, enhanced auth and HiveMQ Cluster.

Mosquitto

The reference open-source broker — both MQTT 3.1.1 and 5.0, over TCP or WebSocket.

EMQX

Massively-scalable broker with shared subscriptions, rule engine and bridge to Kafka. Drop-in.

RabbitMQ Web-MQTT

MQTT-over-WebSocket plugin on port 15675 — the standard pairing for browser + Delphi dashboards.

VerneMQ

Clustered MQTT broker built on Erlang/OTP — both MQTT 3.1.1 and 5.0 modes pass the test suite.

ActiveMQ & Artemis

Apache ActiveMQ’s built-in MQTT listener and the Artemis broker — multi-protocol coexistence with AMQP, STOMP and JMS.

Drop the component, set a few properties, go

Pair a TsgcWebSocketClient with TsgcWSPClient_MQTT, wire OnMQTTConnect / OnMQTTPublish, then Subscribe and Publish.

uses
  sgcWebSocket, sgcWebSocket_Protocol_MQTT_Client,
  sgcWebSocket_Protocol_MQTT_Message;

var
  WSClient: TsgcWebSocketClient;
  MQTT: TsgcWSPClient_MQTT;
begin
  WSClient := TsgcWebSocketClient.Create(nil);
  WSClient.Host := 'www.esegece.com';
  WSClient.Port := 15675;

  MQTT := TsgcWSPClient_MQTT.Create(nil);
  MQTT.Client := WSClient;
  MQTT.Authentication.Enabled  := True;
  MQTT.Authentication.UserName := 'sgc';
  MQTT.Authentication.Password := 'sgc';

  MQTT.OnMQTTConnect := MQTTConnect;
  MQTT.OnMQTTPublish := MQTTPublish;

  WSClient.Active := True;
end;

procedure TForm1.MQTTConnect(Connection: TsgcWSConnection;
  const Session: Boolean; const ReasonCode: Integer;
  const ReasonName: string;
  const ConnectProperties: TsgcWSMQTTCONNACKProperties);
begin
  MQTT.Subscribe('sensors/temperature/#');
end;

procedure TForm1.MQTTPublish(Connection: TsgcWSConnection;
  aTopic, aText: string;
  PublishProperties: TsgcWSMQTTPublishProperties);
begin
  Memo1.Lines.Add(aTopic + ': ' + aText);
end;

// Publish a retained QoS 1 message
MQTT.Publish('sensors/temperature/room1',
  '{"value":22.5,"unit":"C"}', mtqsAtLeastOnce, True);
// uses: sgcWebSocket, sgcWebSocket_Protocol_MQTT_Client
TsgcWebSocketClient *WSClient = new TsgcWebSocketClient(this);
WSClient->Host = "www.esegece.com";
WSClient->Port = 15675;

TsgcWSPClient_MQTT *MQTT = new TsgcWSPClient_MQTT(this);
MQTT->Client = WSClient;
MQTT->Authentication->Enabled  = true;
MQTT->Authentication->UserName = "sgc";
MQTT->Authentication->Password = "sgc";

MQTT->OnMQTTConnect = MQTTConnect;
MQTT->OnMQTTPublish = MQTTPublish;

WSClient->Active = true;

void __fastcall TForm1::MQTTPublish(TsgcWSConnection *Connection,
    UnicodeString aTopic, UnicodeString aText,
    TsgcWSMQTTPublishProperties PublishProperties)
{
  Memo1->Lines->Add(aTopic + ": " + aText);
}

MQTT->Publish("sensors/temperature/room1",
  "{\"value\":22.5,\"unit\":\"C\"}", mtqsAtLeastOnce, true);
using esegece.sgcWebSockets;

var WSClient = new TsgcWebSocketClient();
WSClient.Options.Parameters = "/ws";

var MQTT = new TsgcWSPClient_MQTT();
MQTT.Client = WSClient;
MQTT.Authentication.Enabled  = true;
MQTT.Authentication.UserName = "sgc";
MQTT.Authentication.Password = "sgc";
MQTT.HeartBeat.Enabled  = true;
MQTT.HeartBeat.Interval = 5;

MQTT.OnMQTTConnect += (conn, session, code, name, props) => MQTT.Subscribe("sensors/temperature/#");
MQTT.OnMQTTPublish += (conn, topic, text, props) => Console.WriteLine(topic + ": " + text);

WSClient.Host = "www.esegece.com";
WSClient.Port = 15675;
WSClient.Active = true;

MQTT.Publish("sensors/temperature/room1",
  "{\"value\":22.5,\"unit\":\"C\"}", TmqttQoS.mtqsAtLeastOnce, true);

Specifications & references

Authoritative sources for the protocols this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — Protocol_MQTT Full property, method and event reference for this component.
Demo Project — Demos\Protocols\MQTT Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi, C++ Builder and .NET and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to Get Started with MQTT?

Download the free trial and start building IoT messaging solutions in minutes.