Delphi AMQP Client | AMQP 1.0 & 0.9.1 Components | eSeGeCe

Delphi AMQP Client — AMQP 1.0 and 0.9.1 Components

Two native AMQP client components for Delphi and C++Builder: TsgcWSPClient_AMQP speaks AMQP 0.9.1 to RabbitMQ with exchanges, queues, bindings and consumer acknowledgments, and TsgcWSPClient_AMQP1 speaks OASIS AMQP 1.0 to Azure Service Bus, Apache Qpid and any compliant broker, over a WebSocket or raw-TCP carrier.

Both AMQP versions, one library

AMQP 0.9.1 and AMQP 1.0 share a name but are different wire protocols. sgcWebSockets implements each one natively, so you pick the component that matches your broker.

A Delphi AMQP client connects your VCL or FMX application to enterprise message brokers. AMQP 0.9.1 is the widely-deployed version used by RabbitMQ: you declare exchanges and queues, bind them with routing keys, publish with basic.publish and consume with basic.consume, with transactions and confirms on top. AMQP 1.0 is the OASIS standard used by Azure Service Bus and Apache Qpid: a symmetric link protocol built on sessions, sender links and receiver links, with Claims-Based-Security token helpers for Azure Service Bus SAS and OAuth authentication.

Both components attach to a TsgcWebSocketClient through their Client property and run over a WebSocket or a raw-TCP carrier, so the same code reaches a broker on the standard AMQP ports or tunnels through port 443 past HTTP-only infrastructure.

AMQP 0.9.1

TsgcWSPClient_AMQP: exchanges, queues, bindings, transactions

AMQP 1.0

TsgcWSPClient_AMQP1: sessions, sender and receiver links, CBS tokens

Transports

WebSocket or raw-TCP carrier, TLS optional on both

Platforms

Windows, macOS, Linux, iOS, Android. Delphi 7 through Delphi 13

The full AMQP client surface

Every protocol operation is a method, every broker notification an event.

Exchanges & queues (0.9.1)

DeclareExchange, DeclareQueue and BindQueue build the RabbitMQ routing topology from code: direct, fanout and topic routing with per-channel scoping via OpenChannel.

Publish & consume (0.9.1)

PublishMessage sends to an exchange with a routing key; Consume subscribes a queue and deliveries arrive through OnAMQPBasicDeliver.

CreateSession opens an AMQP 1.0 session, then CreateSenderLink and CreateReceiverLink attach to a node address. Incoming transfers arrive through OnAMQPMessage.

Azure Service Bus (1.0)

Claims-Based-Security helpers wrap the Azure Service Bus SAS / OAuth token flow, so authenticating against a namespace is a property setup rather than a hand-built CBS exchange.

Delivery feedback

OnAMQPMessageSent and OnAMQPMessageSentAck report when a transfer left the client and when the broker settled it.

SASL authentication

Authentication challenges surface through OnAMQPSASLAuthentication (1.0) and OnAMQPAuthentication / OnAMQPChallenge (0.9.1).

HeartBeat

The 0.9.1 client publishes a HeartBeat property so idle connections stay alive across proxies and broker timeouts.

Lifecycle events

OnAMQPConnect, OnAMQPDisconnect, OnAMQPClose and OnAMQPException keep the application informed of the protocol state.

Edition

Both AMQP clients are included in every edition of sgcWebSockets, from Standard through Enterprise and All-Access, and in the .NET library.

Publish and consume in a few lines

Pair the AMQP component with a TsgcWebSocketClient, connect, then declare / attach and go.

uses
  sgcWebSocket, sgcWebSocket_Protocol_AMQP_Client, sgcAMQP_Classes;

var
  WSClient: TsgcWebSocketClient;
  AMQP: TsgcWSPClient_AMQP;
begin
  WSClient := TsgcWebSocketClient.Create(nil);
  WSClient.Host := 'broker.example.com';
  WSClient.Port := 15674;
  WSClient.Options.Parameters := '/ws';

  AMQP := TsgcWSPClient_AMQP.Create(nil);
  AMQP.Client := WSClient;

  AMQP.OnAMQPConnect      := AMQPConnect;
  AMQP.OnAMQPBasicDeliver := AMQPBasicDeliver;

  WSClient.Active := True;
end;

procedure TForm1.AMQPConnect(Sender: TObject);
begin
  AMQP.OpenChannel('ch1');
  AMQP.DeclareExchange('ch1', 'orders', 'direct');
  AMQP.DeclareQueue('ch1', 'orders_in');
  AMQP.BindQueue('ch1', 'orders_in', 'orders', 'create');
  AMQP.Consume('ch1', 'orders_in');

  // Publish a message
  AMQP.PublishMessage('ch1', 'orders', 'create', '{"id":42}');
end;
uses
  sgcWebSocket, sgcWebSocket_Protocol_AMQP1_Client, sgcAMQP1_Classes;

var
  WSClient: TsgcWebSocketClient;
  AMQP1: TsgcWSPClient_AMQP1;
  oSession: TsgcAMQP1Session;
  oSender:  TsgcAMQP1SenderLink;
begin
  WSClient := TsgcWebSocketClient.Create(nil);
  WSClient.Host := 'broker.example.com';
  WSClient.Port := 5673;

  AMQP1 := TsgcWSPClient_AMQP1.Create(nil);
  AMQP1.Client := WSClient;

  AMQP1.OnAMQPConnect      := AMQPConnect;
  AMQP1.OnAMQPMessage      := AMQPMessage;
  AMQP1.OnAMQPSessionOpen  := AMQPSessionOpen;
  AMQP1.OnAMQPLinkOpen     := AMQPLinkOpen;

  WSClient.Active := True;

  oSession := AMQP1.CreateSession;
  oSender  := AMQP1.CreateSenderLink(oSession, '/queue/orders');
  // Receivers handle pushed deliveries through OnAMQPMessage
  AMQP1.CreateReceiverLink(oSession, '/queue/orders');
end;
#include "sgcWebSocket.hpp"
#include "sgcWebSocket_Protocol_AMQP_Client.hpp"

TsgcWebSocketClient* WSClient = new TsgcWebSocketClient(NULL);
WSClient->Host = "broker.example.com";
WSClient->Port = 15674;
WSClient->Options->Parameters = "/ws";

TsgcWSPClient_AMQP* AMQP = new TsgcWSPClient_AMQP(NULL);
AMQP->Client = WSClient;
AMQP->OnAMQPConnect = AMQPConnect;
AMQP->OnAMQPBasicDeliver = AMQPBasicDeliver;

WSClient->Active = true;

// In the OnAMQPConnect handler:
AMQP->OpenChannel("ch1");
AMQP->DeclareExchange("ch1", "orders", "direct");
AMQP->DeclareQueue("ch1", "orders_in");
AMQP->BindQueue("ch1", "orders_in", "orders", "create");
AMQP->Consume("ch1", "orders_in");
AMQP->PublishMessage("ch1", "orders", "create", "{\"id\":42}");

AMQP 0.9.1 or AMQP 1.0

Choose by broker, not by version number. If the other side is RabbitMQ, use the AMQP 0.9.1 component: it maps one-to-one onto the RabbitMQ model of exchanges, queues and bindings. If the other side is Azure Service Bus, Apache Qpid or another broker that advertises the OASIS standard, use the AMQP 1.0 component and its session / link model.

Both ship in the same package, so mixed environments are fine: one application can hold a 0.9.1 connection to RabbitMQ and a 1.0 connection to Azure Service Bus side by side, each on its own TsgcWebSocketClient carrier.

More on AMQP in sgcWebSockets

AMQP 0.9.1 protocol page

Full reference for TsgcWSPClient_AMQP: properties, methods, events and the demo project.

AMQP 1.0 protocol page

Full reference for TsgcWSPClient_AMQP1: sessions, links and CBS authentication.

Real-time picker

When to choose AMQP over MQTT, WebSocket, SSE or HTTP/2 push.

Blog: Exchanges and queues

The AMQP 0.9.1 routing model explained with Delphi code.

Blog: Publishing messages

Publish patterns and delivery options from the Delphi client.

Blog: Azure Service Bus CBS auth

Claims-Based-Security tokens against Azure Service Bus over AMQP 1.0.

Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Connect to your broker today

Download the trial. The AMQP 0.9.1 and AMQP 1.0 demo projects compile out of the box.