Wednesday, April 1, 2009

Another Way of Starting ActiveMQ Broker in Spring

I had posted a blog about running an ActiveMQ broker in Spring. Recently, I found an alternative way to start an ActiveMQ message broker in spring environment by injecting a bean based on org.apache.activemq.xbean.XBeanBrokerService:


<bean id="broker" class="org.apache.activemq.xbean.XBeanBrokerService">
<property name="useJmx" value="true"/>
<!-- this tells it to create a filesystem store -->
<property name="persistent" value="true"/>
<property name="brokerName" value="mySpringBroker"/>
<!--the queues/topics that this broker starts with-->
<property name="destinations">
<list>
<ref bean="destination1"/>
<ref bean="destination2"/>
</list>
</property>
<property name="transportConnectors">
<list>
<!-- an in vm connector which is nice and fast -->
<bean class="org.apache.activemq.broker.TransportConnector">
<property name="uri" value="vm://localhost"/>
</bean>
<!-- a connection for external clients specifying the IP of machine deploying the broker, something like tcp://10.10.10.10:61636. Here read from a properties file but can be hard-coded as well-->
<bean class="org.apache.activemq.broker.TransportConnector">
<property name="uri" value="${broker.transportExternalConnectorUri}"/>
</bean>
</list>
</property>
</bean>

<bean id="destination1" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="com.saveenkumar.myQueue1"/>
</bean>

<bean id="destination2" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="com.saveenkumar.myQueue2"/>
</bean>

In fact,the package org.apache.activemq.xbean provides various options (beans) to start the broker in a spring environment.

No comments: