ActiveMQ Clustered and Bulletproof
Warning: file_get_contents(http://feeds.delicious.com/v2/json/urlinfo/data?url=http%3A%2F%2Fstephennimmo.com%2Fblog%2F2009%2F11%2F03%2Factivemq-clustered-and-bulletproof%2F) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 999 Unable to process request at this time -- error 999 in /home1/stephenn/public_html/blog/wp-content/plugins/digg-digg/dd.class.php on line 866
It's easy to create a clustered instance of ActiveMQ and have your clients connect via multicast. This gives you the ability to create ActiveMQ instances all over the place, have them autodiscover each other and failover seamlessly and automatically. Here's the ActiveMQ configuration.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="MyBroker" dataDirectory="${activemq.base}/data">
<destinations>
<queue physicalName="MyQueue" />
</destinations>
<transportConnectors>
<transportConnector name="openwire" uri="tcp://localhost:0" discoveryUri="multicast://default"/>
</transportConnectors>
<networkConnectors>
<networkConnector uri="multicast://default"/>
</networkConnectors>
<persistenceAdapter>
<memoryPersistenceAdapter/>
</persistenceAdapter>
</broker>
<jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
<connectors>
<nioConnector port="8161"/>
</connectors>
<handlers>
<webAppContext contextPath="/admin" resourceBase="${activemq.base}/webapps/admin" logUrlOnStart="true"/>
</handlers>
</jetty>
</beans>
And here is the Spring code for the client.
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL"> <value>discovery:(multicast://default)</value> </property> </bean> <bean id="destination" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg index="0"> <value>MyQueue</value> </constructor-arg> </bean> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory"> <bean class="org.springframework.jms.connection.SingleConnectionFactory"> <property name="targetConnectionFactory" ref="jmsConnectionFactory" /> </bean> </property> </bean>
If you will notice, the ActiveMQ client uses the discovery mechanisms for finding the queue, which allows it to connect to any piece of hardware without actually having to know physical locations. You can replace your multicast://default (which happens to be multicast://239.255.2.3:6155) with whatever multicast address you would like. You could even DNS-it-up and have a url look like multicast://MyBroker.mydomain.com:6166.
Enjoy.
http://activemq.apache.org/multicast-transport-reference.html
December 1st, 2009 - 11:26
Very cool. I will come back to this article again.
May 3rd, 2010 - 01:52
great post as usual!