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.
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.