Red Hat DocumentationFuse Message BrokerToggle FramesPrintFeedback

Starting a Broker with Maven

Overview

When developing messaging applications it can be helpful to have a test broker start up automatically when running the application. This can be accomplished using Fuse Message Broker's Apache Maven plug-in. The plug-in can be used directly from the command line or it can be included as part of a project's POM.

The Maven plug-in treats the broker as a part of the project's build and test environment. Maven will download all of the Fuse Message Broker libraries from the configured Maven repositories. The plug-in will store all of the broker's data in the project's target folder.

Note

Starting broker in a production environment from Maven is not recommended.

Using the command line

If a basic broker will suffice for testing an application, the Fuse Message Broker Maven plug-in can be loaded from the command line as shown in Example 17.

Example 17. Using the Maven Plug-in from the Command Line

mvn org.apache.activemq.tooling:maven-activemq-plugin:5.5.1-fuse-00-xx:run

This will create a broker that:

  • listens for client connections on tcp://localhost:61616

  • does not use JMX

  • does not persist messages

Using the POM

If the basic broker provided by adding the plug-in on the command line is insufficient for test an application the plug-in can be included in the project's POM. When included in a POM, the Fuse Message Broker plug-in uses a configuration URI to configure the broker. The plug-in can also set system properties when starting the broker.

Table 3 describes the configuration properties used by the Fuse Message Broker Maven plug-in.

Table 3. Maven Configuration Properties

PropertyDefaultDescription
configUri broker:(tcp://localhost:61616) ?useJmx=false&persistent=false Specifies the configuration URI used to configure the broker. See ???? for more information.
fork falseSpecifies whether the broker is started in a separate thread. Having the broker start in a separate thread can be useful for integration testing.
systemProperties  Specifies a collection of system properties that will be set.

To start the configured broker when running the project use mvn activemq:run.

Example 18 shows a POM fragment that configures the Fuse Message Broker plug-in to start a broker using the activemq.xml configuration file on the project's class path.

Example 18. Using the Maven Plug-in from a POM

<project ... >

  ...

  <repositories>
  <!-- FuseSource maven repositories -->
    <repository>
      <id>fusesource.releases</id>
      <name>FuseSoure releases repository</name>
      <url>http://repo.fusesource.com/maven2/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
    <repository>
      <id>fusesource.snapshots</id>
      <name>FuseSource Snapshot Repository</name>
      <url>http://repo.fusesource.com/maven2-snapshot</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>
  </repositories>

  <pluginRepositories>
  <!-- FuseSource maven repositories -->
    <pluginRepository>
      <id>fusesource.releases</id>
      <name>FuseSoure releases repository</name>
      <url>http://repo.fusesource.com/maven2/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </pluginRepository>
    <pluginRepository>
      <id>fusesource.snapshots</id>
      <name>FuseSource Snapshot Repository</name>
      <url>http://repo.fusesource.com/maven2-snapshot</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </pluginRepository>
  </pluginRepositories>

  ...

  <build>    
    <plugins>
      <plugin>
        <groupId>org.apache.activemq.tooling</groupId>
        <artifactId>maven-activemq-plugin</artifactId>
        <version>5.5</version>
        <configuration>
          <configUri>xbean:activemq.xml</configUri>
          <fork>false</fork>
        </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>
    </plugins>
  </build>
</project>

Comments powered by Disqus