STOMP ActiveMQ Client Component: sgcMQ | eSeGeCe

STOMP ActiveMQ Client

TsgcWSPClient_STOMP_ActiveMQ is the STOMP client tuned for Apache ActiveMQ. It adds queue and topic helpers over ActiveMQ's destination naming, typed header objects on every event, and an ActiveMQ_Options property for the broker-specific settings that durable subscriptions need.

TsgcWSPClient_STOMP_ActiveMQ

Everything in the generic STOMP client still applies. The additions are the destination helpers, the ActiveMQ-named events and the broker options.

Component class

TsgcWSPClient_STOMP_ActiveMQ

Specification

STOMP 1.0, 1.1 and 1.2

Transport

TCP (61613) or TLS (61612)

Languages

Delphi, C++ Builder

Transport: plain TCP and TLS. sgcMQ talks to ActiveMQ over plain TCP and TLS. ActiveMQ's STOMP-over-WebSocket connector is a WebSocket endpoint, so reaching it requires a sgcWebSockets package, which provides the WebSocket client.

Subscribe to a queue, publish to it

This sample uses ActiveMQ's native STOMP port, 61613. For an encrypted link, switch on TLS on the carrier and use the broker's stomp+ssl connector on port 61612.

uses
  sgcTCP_Client_WS, sgcWebSocket_Classes, sgcWebSocket_Protocols,
  sgcWebSocket_Protocol_STOMP_Broker_Client,
  sgcWebSocket_Protocol_STOMP_ActiveMQ_Client;

var
  TCPClient: TsgcTCPClient;
  STOMP: TsgcWSPClient_STOMP_ActiveMQ;
begin
  TCPClient := TsgcTCPClient.Create(nil);
  TCPClient.Host := 'broker.example.com';
  TCPClient.Port := 61613;

  STOMP := TsgcWSPClient_STOMP_ActiveMQ.Create(nil);
  STOMP.Client := TCPClient;
  STOMP.ActiveMQ_Options.ClientId := 'delphi-consumer-1';
  STOMP.Authentication.Enabled  := True;
  STOMP.Authentication.UserName := 'admin';
  STOMP.Authentication.Password := 'admin';

  STOMP.OnActiveMQConnected := ActiveMQConnected;
  STOMP.OnActiveMQMessage   := ActiveMQMessage;

  TCPClient.Active := True;
end;

procedure TForm1.ActiveMQConnected(Connection: TsgcWSConnection;
  Headers: TsgcWSActiveMQSTOMPHeadersConnected);
begin
  STOMP.SubscribeQueue('orders');
  STOMP.PublishQueue('orders', '{"id":42}');
end;

procedure TForm1.ActiveMQMessage(Connection: TsgcWSConnection;
  MessageText: string; Headers: TsgcWSActiveMQSTOMPHeadersMessage;
  Subscription: TsgcWSBrokerSTOMPSubscriptionItem);
begin
  Memo1.Lines.Add(Headers.Destination + ': ' + MessageText);
end;
// include: sgcTCP_Client_WS.hpp, sgcWebSocket_Protocols.hpp,
// sgcWebSocket_Protocol_STOMP_ActiveMQ_Client.hpp

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

TsgcWSPClient_STOMP_ActiveMQ *STOMP =
  new TsgcWSPClient_STOMP_ActiveMQ(this);
STOMP->Client = TCPClient;
STOMP->ActiveMQ_Options->ClientId = "cbuilder-consumer-1";
STOMP->Authentication->Enabled  = true;
STOMP->Authentication->UserName = "admin";
STOMP->Authentication->Password = "admin";

STOMP->OnActiveMQConnected = ActiveMQConnected;
STOMP->OnActiveMQMessage   = ActiveMQMessage;

TCPClient->Active = true;

// In the OnActiveMQConnected handler:
STOMP->SubscribeQueue("orders");
STOMP->PublishQueue("orders", "{\"id\":42}");

Key properties & methods

The members you reach for most often.

Queues

SubscribeQueue, PublishQueue and UnSubscribeQueue take the plain queue name and build the /queue/ destination, with durable, exclusive and ack-mode arguments.

Topics

SubscribeTopic, PublishTopic and UnSubscribeTopic do the same for /topic/ destinations, which is where durable subscriptions matter most.

Generic destinations

SubscribeEx, PublishEx and UnSubscribeEx take a raw destination string for anything the named helpers do not cover.

Broker options

ActiveMQ_Options carries the ActiveMQ-specific settings, including the ClientId the broker uses to recognise a returning durable subscriber.

Durable subscriptions

The subscribe helpers take a Durable flag, so a topic subscriber can disconnect and later collect the messages the broker held for it.

Typed headers

OnActiveMQMessage delivers a TsgcWSActiveMQSTOMPHeadersMessage plus the matching subscription item, so destination, message id and ack mode are properties.

Acknowledgement

Pass an ack mode when subscribing, then call ACK or NACK with the message id. In ackAuto the broker considers a message delivered as soon as it is sent.

Message options

Every publish helper accepts a content type, an optional transaction name and a message-options object for ActiveMQ headers such as priority, persistence and expiration.

Connection

Client, Authentication, HeartBeat, Versions and Options behave exactly as they do on the generic STOMP client.

Keep exploring

Online HelpFull API reference and usage guide.
Generic STOMP ClientThe base component with the standard frame set.
AMQP 1.0 ClientActiveMQ Artemis also speaks AMQP 1.0.
Download Free TrialRun against a local ActiveMQ broker.
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 talk to ActiveMQ over STOMP from Delphi or C++ Builder.