Thursday, October 15, 2009

Query Statistics for Apache ActiveMQ

Apache ActiveMQ has extensive support for JMX, but if you want to find out the running state of ActiveMQ from your application or from the one of the number of cross-language clients - your options are a bit limited.

ActiveMQ supports Broker plugins, which allows the default functionality to be extended, and new with version 5.3 of Apache ActiveMQ is a Statistics plugin, which enables statistics about the running broker, or Queues and Topics to be queried. 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. To query the running statistics of a the message broker, send an empty message to a Destination (Queue or Topic) named ActiveMQ.Statistics.Broker, and set the replyTo (jmsReplyTo if using JMS) field with the Destination you want to receive the result on. The statistics plugin will send a MapMessage filled with the statistics for the running ActiveMQ broker - e.g.

Queue replyTo = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(replyTo);


Queue query = session.createQueue("ActiveMQ.Statistics.Broker");
MessageProducer producer = session.createProducer(query);
Message msg = session.createMessage();
msg.setJMSReplyTo(replyTo);
producer.send(msg);


MapMessage reply = (MapMessage) consumer.receive();


for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
String name = e.nextElement().toString();
System.err.println(name+"="+reply.getObject(name));
}

You should see output like this:
vm=vm://localhost
memoryUsage=0
storeUsage=3330
tempPercentUsage=0
ssl=
openwire=tcp://localhost:50059
brokerId=ID:bigmac-50057-1253605065511-0:0
consumerCount=2
brokerName=localhost
expiredCount=0
dispatchCount=1
maxEnqueueTime=5.0
storePercentUsage=0
dequeueCount=0
inflightCount=1
messagesCached=0
tempLimit=107374182400
averageEnqueueTime=5.0
stomp+ssl=
memoryPercentUsage=0
size=10
tempUsage=0
producerCount=1
minEnqueueTime=5.0
dataDirectory=/Users/rajdavies/dev/projects/activemq/activemq-core/activemq-data
enqueueCount=10
stomp=
storeLimit=107374182400
memoryLimit=67108864



Similarly, 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.
e.g.


Queue replyTo = session.createTemporaryQueue();
 MessageConsumer consumer = session.createConsumer(replyTo);
 Queue testQueue = session.createQueue("Test.Queue");
 MessageProducer producer = session.createProducer(null);
 Queue query = session.createQueue("
ActiveMQ.Statistics.Destination" +    testQueue.getQueueName());

 Message msg = session.createMessage();
       
  producer.send(testQueue,msg)
   msg.setJMSReplyTo(replyTo);
   producer.send(query,msg);
  MapMessage reply = (MapMessage) consumer.receive();
  assertNotNull(reply);
  assertTrue(reply.getMapNames().hasMoreElements());
       
  for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
            String name = e.nextElement().toString();
            System.err.println(name+"="+reply.getObject(name));
   }

       
You should see:



memoryUsage=0
dequeueCount=0
inflightCount=0
messagesCached=0
averageEnqueueTime=0.0
destinationName=queue://Test.Queue
size=1
memoryPercentUsage=0
producerCount=0
consumerCount=0
minEnqueueTime=0.0
maxEnqueueTime=0.0
dispatchCount=0
expiredCount=0
enqueueCount=1
memoryLimit=67108864


You can also use wildcards too, and receive a separate message for every destination matched.










Tuesday, October 13, 2009

Apache ActiveMQ 5.3 Released!

ActiveMQ 5.3 is finally released - and probably the biggest lesson is that going forward, we need to release far more frequently!

Here are some highlights:
  • We are making it a lot more obvious how to scales brokers vertically, to 10s of thousands of Queues/Topics - by including more example configurations.
  • New incarnation of KahaDB one of the persistent options we support. This provides vastly improved recovery times and scalability.
  • We've upgraded to the latest and greatest Apache Camel 2.0 - allowing for enterprise integration patterns to be run right inside the worlds most popular message broker
  • Support for getting broker statistics from languages other than Java
  • Message Expiration support directly in-store (any message store - and we support a few)
  • More extensive advisory messages
  • Enhancements to Master/Slave - including  more flexibility for starting slave brokers
  • NIO and SSL support for the mostly widely supported messaging transport - STOMP
  • over 300 issues resolved since version 5.2
Apache ActiveMQ is used in thousands of production environments for delivering high performance and reliable messaging under extreme load. Being an Apache project, it is supported by a diverse community of developers with extensive knowledge of building messaging solutions. Why not go and give it a spin ? - try the latest download!