AMQP 1.0 Client Component: sgcMQ | eSeGeCe

AMQP 1.0 Client

TsgcWSPClient_AMQP1 implements OASIS AMQP 1.0, also published as ISO/IEC 19464. Despite the shared name this is a different protocol from AMQP 0.9.1, with a different object model: a container opens sessions, sessions carry sender and receiver links, and links move messages under credit-based flow control. It is the protocol Azure Service Bus and Event Hubs speak.

TsgcWSPClient_AMQP1

Sessions and links are addressed by the name you give them, so 'session1' and 'sender1' identify the same objects across every later call.

Component class

TsgcWSPClient_AMQP1

Specification

OASIS AMQP 1.0 (ISO/IEC 19464)

Transport

TCP (5672) or TLS (5671)

Languages

Delphi, C++ Builder

Transport: plain TCP and TLS. sgcMQ connects over plain TCP and TLS. If you need AMQP over WebSocket, that requires a sgcWebSockets package, which provides the WebSocket client.

A sender link points at a target node on the broker, a receiver link at a source node. Once a receiver is attached, deliveries arrive on OnAMQPMessage.

uses
  sgcTCP_Client_WS, sgcWebSocket_Protocols,
  sgcWebSocket_Protocol_AMQP1_Client, sgcAMQP1_Classes, sgcAMQP1_Frames;

var
  TCPClient: TsgcTCPClient;
  AMQP1: TsgcWSPClient_AMQP1;
begin
  TCPClient := TsgcTCPClient.Create(nil);
  TCPClient.Host := 'broker.example.com';
  TCPClient.Port := 5672;

  AMQP1 := TsgcWSPClient_AMQP1.Create(nil);
  AMQP1.Client := TCPClient;
  AMQP1.AMQPOptions.ContainerId := 'delphi-app';
  AMQP1.AMQPOptions.Authentication.AuthType := amqp1authSASLPlain;
  AMQP1.AMQPOptions.Authentication.Username := 'guest';
  AMQP1.AMQPOptions.Authentication.Password := 'guest';

  AMQP1.OnAMQPConnect := AMQPConnect;
  AMQP1.OnAMQPMessage := AMQPMessage;

  TCPClient.Active := True;
end;

procedure TForm1.AMQPConnect(Sender: TObject;
  const aOpen: TsgcAMQP1FrameOpen);
begin
  AMQP1.CreateSession('session1');

  // Sender link: name, then the target node address
  AMQP1.CreateSenderLink('session1', 'sender1', '/queue/orders');

  // Receiver link: deliveries arrive on OnAMQPMessage
  AMQP1.CreateReceiverLink('session1', 'receiver1', '/queue/orders');

  AMQP1.SendMessage('session1', 'sender1', '{"id":42}');
end;
#include "sgcTCP_Client_WS.hpp"
#include "sgcWebSocket_Protocols.hpp"
#include "sgcWebSocket_Protocol_AMQP1_Client.hpp"

TsgcTCPClient *TCPClient = new TsgcTCPClient(this);
TCPClient->Host = "broker.example.com";
TCPClient->Port = 5672;

TsgcWSPClient_AMQP1 *AMQP1 = new TsgcWSPClient_AMQP1(this);
AMQP1->Client = TCPClient;
AMQP1->AMQPOptions->ContainerId = "cbuilder-app";
AMQP1->OnAMQPConnect = AMQPConnect;
AMQP1->OnAMQPMessage = AMQPMessage;

TCPClient->Active = true;

// In the OnAMQPConnect handler. SendMessage is SendMessage_ in C++ Builder.
AMQP1->CreateSession("session1");
AMQP1->CreateSenderLink("session1", "sender1", "/queue/orders");
AMQP1->CreateReceiverLink("session1", "receiver1", "/queue/orders");
AMQP1->SendMessage_("session1", "sender1", "{\"id\":42}");

Key properties & methods

The members you reach for most often.

Sessions

CreateSession returns a TsgcAMQP1Session and CloseSession tears it down. A session is the unit of ordering and windowing between the two containers.

CreateSenderLink attaches to a target node, CreateReceiverLink to a source node, and CloseLink detaches either. A session can hold several links up to MaxLinksPerSession.

Sending

SendMessage(session, link, text) transfers a message, with an overload taking a full TsgcAMQP1Message when you need application properties, an id or annotations.

Receiving

An attached receiver link pushes deliveries to OnAMQPMessage. GetMessage pulls one synchronously with a timeout when a blocking style suits better.

Delivery feedback

OnAMQPMessageSent fires when the transfer leaves the client, OnAMQPMessageSentAck when the broker settles it. The two are separate on purpose.

Authentication

AMQPOptions.Authentication.AuthType selects amqp1authSASLPlain, amqp1authSASLAnonymous, amqp1authSASLExternal or none. OnAMQPSASLAuthentication reports the negotiation.

Azure helpers

CreateCBSLink and PutCBSToken implement Claims-Based Security. CreateAzureCbsSasToken builds a Service Bus SAS token, CreateAzureCbsJWT an OAuth bearer token.

Flow control

AMQPOptions.CreditSize and WindowSize govern how much a receiver will accept before it issues more credit. MaxFrameSize and ChannelMax are negotiated on open.

Frame inspection

OnAMQPBeforeReadFrame and OnAMQPBeforeWriteFrame hand you each raw frame with a Handled flag, which is invaluable when a broker behaves unexpectedly.

Keep exploring

Online HelpFull API reference and usage guide.
AMQP 0.9.1 ClientThe other AMQP, with exchanges, queues and bindings.
Download Free TrialRun the client against Azure Service Bus, Artemis or Qpid.
PricingSingle, Team and Site licenses with full source code.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and attach your first AMQP 1.0 link from Delphi or C++ Builder.