Query Statistics for Apache ActiveMQ with Delphi

Last October, Rob Davies wrote about the new Statistics plugin which is included in Apache ActiveMQ 5.3 and yesterday I found that it works very well using Delphi and the Habari ActiveMQ Client library (using the Stomp protocol) too.

Broker Configuration

To configure ActiveMQ to use the statistics plugin just add the following to the ActiveMQ XML configuration:

<plugins>
  <statisticsBrokerPlugin/>
</plugins>

The statistics plugin looks for messages sent to particular destinations.

Query running broker statistics

To query the running statistics of the message broker, the client sends an empty message to a Destination (Queue or Topic) named ActiveMQ.Statistics.Broker, and set the JMSReplyTo field with the Destination you want to receive the result on. The statistics plugin will send a JMS MapMessage filled with the statistics for the running ActiveMQ broker.

Until now Habari ActiveMQ Client had no support for a Java(tm) JMS MapMessage. Fortunately, using the ActiveMQ message transformation extensions, a Stomp client can request a JSON or XML transformation for the original Java object. This is what I have implemented yesterday:

Introducing JMS MapMessage

To receive JMS MapMessage objects, the connection needs a message transformer which uses a transformation id for JSON or XML map messages. A new Map message transformer is now included and can be used for the connection:

with (Connection as IMessageTransfomerSupport) do
begin
  MessageTransformer := TBTMessageTransformerXMLMapOmni.Create(nil);
end;

Next, a Reply Queue destination needs to be configured so that it listens to the answer for the request. When the broker receives the request message, it will send a MapMessage to this reply queue. The code then iterates over the map entries and writes them to the console:

 // read the result message
 Reply := Consumer.Receive(3000) as IMapMessage;

 // list the map key/values
 if Assigned(Reply) then
 begin
   MapNames := Reply.GetMapNames;
   for I := 0 to Length(MapNames) - 1 do
   begin
     Key := MapNames[I];
     WriteLn(Key + '=' + Reply.GetString(Key));
   end;
 end

Query destination statistics

If you want to query the statistics on a Destination, send a message to the Destination name, prepended with ActiveMQ.Statistics.Destination. For example, to retrieve the statistics on a Queue named test.foo send an empty message to the Queue ActiveMQ.Statistics.DestinationTest.Foo.


Query Statistics for Apache ActiveMQ with Delphi

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s