Camel actually started off as a sub-project of ActiveMQ - so the integration between the two is excellent (although it will be even better in ActiveMQ 6).
I blogged a while ago about the new Statistics Plugin - that you can use to request a message from the ActiveMQ broker about its running statistics (just in case you don't want to use JMX). Now it would kinda nice to automatically send these messages out from the ActiveMQ message broker periodically. Well its really easy to do that ...
Firstly enable the statics plugin in the ActiveMQ broker configuration and also import a camel config - e.g.
<beans>
<broker brokerName="testBroker" xmlns="http://activemq.apache.org/schema/core">
<transportConnectors>
<transportConnector uri="tcp://localhost:61616"/>
</transportConnectors>
</broker>
<import resource="camel.xml"/>
</beans>
Then in the camel XML configuration define an embedded ActiveMQ Connection -
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://testBroker?create=false&waitForStart=1000" />
<property name="userName" value="DEFAULT_VALUE"/>
<property name="password" value="DEFAULT_VALUE"/>
</bean>
</property>
</bean>
Note: the vm:// transport (uses a broker's name to locate it in the same JVM)
Then just add a Camel route in the Camel configuration which uses a Timer to request statistics from the broker and publish them on a Topic every second - e.g:
<route>
<from uri="timer://foo?fixedRate=true&period=1000"/>
<inOut uri="activemq:queue:ActiveMQ.Statistics.DestinationTest.Queue"/>
<to uri="activemq:topic:Statistics.Topic"/>
</route>
Simple!
We are going to be on the road doing the popular Fuse days again from September - but in the meantime - you can find out more about Apache Camel, ActiveMQ and ServiceMix from our Fuse webinars.
1 comment:
Just a quick comment. If your using spring 3 it looks like you need to place the plugins tag alphabetically in activemq.xml.
I placed it after persistenceAdapter
Post a Comment