Delphi Azure SDK — IoT Hub, Service Bus, OAuth2 & more

A native Pascal toolkit for Microsoft Azure: connect devices to Azure IoT Hub over MQTT or AMQP, send / receive messages on Azure Service Bus over AMQP 1.0 with CBS authentication, sign requests with Azure AD OAuth2 and JWT, talk to Azure OpenAI, and generate strongly-typed clients for any Azure REST API from its OpenAPI specification — all from a coherent set of sgcWebSockets components.

Pascal components for every Azure surface

No .NET runtime, no Azure CLI, no PowerShell bridge — just Delphi components that speak HTTPS, MQTT, AMQP and OAuth2 directly to the Azure endpoints.

Microsoft Azure exposes hundreds of REST APIs and a handful of streaming protocols: HTTPS for the resource manager, Cognitive Services, Storage, Cosmos DB and Azure OpenAI; MQTT 3.1.1 / 5 for IoT Hub device-to-cloud messaging; AMQP 1.0 with CBS (Claims-Based Security) authentication for Service Bus queues, topics and Event Hubs. sgcWebSockets ships native components for all three transports — TsgcWSAPI_AzureIoT for IoT Hub, the AMQP 1.0 client for Service Bus, and TsgcHTTPClient with OAuth2 + JWT helpers for everything else — plus the sgcOpenAPI code generator that emits Pascal classes for any Azure API documented in OpenAPI.

Authentication maps cleanly to Pascal: a tenant ID, an application (client) ID and either a client secret or a certificate-backed private key drive the Azure AD OAuth2 client-credentials flow; the resulting JWT access token carries one or more https://management.azure.com/.default (or service-specific) scopes and goes into every Authorization: Bearer header. For Service Bus, the CBS handshake reuses the same token as an AMQP frame on a special $cbs link before any data link is opened. The library handles the lifecycle automatically.

Core components

TsgcWSAPI_AzureIoT, TsgcAMQPClient, TsgcHTTPClient, TsgcOAuth2Client, TsgcJWTClient.

Transport

HTTPS / HTTP/2, MQTT 3.1.1 + 5 over TCP / WebSocket, AMQP 1.0 over TCP / WebSocket.

Platforms

Windows, macOS, Linux, iOS, Android, .NET.

Code generator

sgcOpenAPI consumes Azure REST specifications and emits Pascal client classes.

First-class wrappers + generated SDKs

Azure IoT Hub

TsgcWSAPI_AzureIoT — MQTT 3.1.1 / 5 with SAS-token or X.509 mutual TLS authentication, device twin, direct methods, cloud-to-device messages, file uploads.

Azure Service Bus (AMQP 1.0)

The TsgcAMQPClient speaks AMQP 1.0 with the CBS authentication handshake required by Service Bus — queues, topics, subscriptions, sessions, scheduled messages and dead-letter routing.

Azure Event Hubs

Same AMQP 1.0 client — partitioned event streaming for high-throughput telemetry ingestion, with consumer-group offset management.

Azure Storage

Blob, Queue and Table storage via HTTPS with Shared Key or Azure AD authentication — uploads, downloads, SAS URLs and lease management.

Azure OpenAI

TsgcHTTP_API_OpenAI talks to your Azure OpenAI resource — chat, embeddings, function calling and streaming, with deployment IDs in place of model names.

Azure Functions

HTTPS POST / GET invocations against function URLs, with function-key, system-key or Azure AD authentication.

Azure Cognitive Services

Speech (STT / TTS), Vision, Language, Translator and Document Intelligence — all reachable through HTTPS with Bearer or subscription-key authentication.

Generated Azure SDKs

sgcOpenAPI emits Pascal client classes for any Azure REST API that publishes an OpenAPI document — Resource Manager, Key Vault, Cosmos DB, App Service, Logic Apps and friends.

Azure AD OAuth2 + JWT, end to end

Azure’s modern identity model is uniform: register an application in Azure AD, grant it the API permissions it needs (e.g. Service Bus Data Owner, IoT Hub Data Contributor, Cognitive Services User), and authenticate with the OAuth2 client-credentials flow (for service-to-service) or the authorisation-code flow (for end-user data). TsgcOAuth2Client drives both; TsgcJWTClient signs the client assertion when you prefer certificate-based authentication over a shared secret. The resulting bearer token feeds every HTTPS call directly, and the CBS frame on Service Bus / Event Hubs reuses the same JWT — no duplicate credential management.

Send a message to Azure Service Bus over AMQP 1.0

A 25-line snippet that authenticates with a shared-access-signature, opens an AMQP 1.0 connection with the CBS handshake and publishes to a queue.

uses
  sgcAMQP_Client, sgcAMQP_Classes_1_0;

var
  vAMQP: TsgcAMQPClient;
begin
  vAMQP := TsgcAMQPClient.Create(nil);
  try
    vAMQP.Version       := amqp100;
    vAMQP.Host          := 'my-namespace.servicebus.windows.net';
    vAMQP.Port          := 5671;
    vAMQP.TLS           := True;

    // CBS authentication with a SAS token
    vAMQP.Authentication.Mode        := amqpAuthCBS;
    vAMQP.Authentication.User        := 'RootManageSharedAccessKey';
    vAMQP.Authentication.Password    := 'SharedAccessSignature sr=...&sig=...&se=...&skn=RootManageSharedAccessKey';

    vAMQP.Connect;
    try
      vAMQP.SendMessage('orders',
        '{"orderId":1234,"total":42.50}');
    finally
      vAMQP.Disconnect;
    end;
  finally
    vAMQP.Free;
  end;
end;

MQTT device clients with SAS tokens

Azure IoT Hub accepts MQTT 3.1.1 or 5 (with the IoT Hub-specific topic schema) over TCP port 8883 or WebSocket port 443. TsgcWSAPI_AzureIoT handles the connection, the SAS-token signing, device twin synchronisation, direct-method dispatch and the cloud-to-device message channel — with the same source code on Windows, Linux and the mobile targets.

uses
  sgcWSAPI_AzureIoT;

var
  vIoT: TsgcWSAPI_AzureIoT;
begin
  vIoT := TsgcWSAPI_AzureIoT.Create(nil);
  try
    vIoT.Authentication.SharedAccessKey.HostName := 'my-hub.azure-devices.net';
    vIoT.Authentication.SharedAccessKey.DeviceId := 'device-001';
    vIoT.Authentication.SharedAccessKey.Key      := 'BASE64-DEVICE-KEY==';

    vIoT.OnMQTTConnect           := DoMQTTConnect;
    vIoT.OnMQTTPublish           := DoMQTTPublish;
    vIoT.OnDeviceTwinDesired     := DoDeviceTwinDesired;
    vIoT.OnDirectMethod          := DoDirectMethod;

    vIoT.Active := True;
  finally
    vIoT.Free;
  end;
end;

Three steps to your first Azure call

1. Install

Drop sgcWebSockets into your Delphi or C++Builder IDE — one package per Delphi version 7 through 13. Download the trial.

2. Register an Azure AD app

Create an app registration, generate a client secret or upload a certificate, and grant API permissions for the services you intend to call.

3. Drop a component

For IoT use TsgcWSAPI_AzureIoT, for Service Bus / Event Hubs use the AMQP 1.0 client, for anything REST use TsgcHTTPClient + TsgcOAuth2Client.

Azure Service Bus + CBS authentication over AMQP 1.0

Step-by-step walk-through of the AMQP CBS handshake required by Azure Service Bus and Event Hubs.

Azure IoT file uploads

Use IoT Hub’s blob-storage upload flow to ship telemetry payloads larger than the MQTT message limit.

Azure OpenAI from RAD Studio

Point TsgcHTTP_API_OpenAI at your Azure OpenAI deployment for chat, embeddings and function calling.

Ship Azure integrations in your Delphi app today

Download the trial — IoT Hub, Service Bus (AMQP 1.0) and Azure OpenAI demos ship ready to compile.