Saturday, July 2, 2011

Automate Active MQ Broker start/stop through maven


While writing integration test most of the time you need to start and stop Active MQ manually which most of you won’t prefer doing by this I mean get things automated . This can be easily done using maven(I have really started loving this tool ) plugin where in before you automated test start maven while start the Active MQ service . Below are the things that the developer had to do in maven
First you need to configure pom with the Maven plugin for Active MQ details
<plugin>
<groupId>org.apache.activemq.tooling</groupId>
<artifactId>maven-activemq-plugin</artifactId>
<version>5.4.0</version>
<configuration>
<configUri>xbean:file:src/main/resources/activemq.xml</configUri>
<fork>true</fork>
<systemProperties>
<property>
<name>javax.net.ssl.keyStorePassword</name>
<value>password</value>
</property>
<property>
<name>org.apache.activemq.default.directory.prefix</name>
<value>${project.build.directory}/target/</value>
</property>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-xbean</artifactId>
<version>6.1.11</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-activemq</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</plugin>


Secondly , we will have to create activemq.xml which is the configuration file for Active MQ .
<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
  ">
  <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="./data">
  <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="20 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="1 gb" name="foo"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="100 mb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>
    <!-- The transport connectors ActiveMQ will listen to -->
    <transportConnectors>
      <transportConnector name="openwire" uri="tcp://0.0.0.0:61616" />
      <transportConnector name="stomp" uri="stomp://0.0.0.0:61613" />
    </transportConnectors>
  </broker>
</beans>

That’s it , once you are done with the above two steps you need to open up your system terminal and run
mvn clean install activemq:run -Dmaven.test.skip=true

No comments:

Post a Comment