Running an ActiveMQ Broker with Maven

By | February 22, 2016

This short example will show you how to run an ActiveMQ broker with Maven using the ActiveMQ Maven plug-in, as part of running tests.
In the example I will implement a Java unit test, but I think that running ActiveMQ with Maven will be more useful when, for instance, wanting to run a broker in connection to running a Gatling stress tests (which can also be run using Maven).
The example consists of three files:

  • A Maven pom.xml file.
    Manages dependencies as well as contains the configuration of the ActiveMQ Maven plug-in etc.
  • An activemq.xml file.
    Contains broker configuration.
  • A JUnit test class implemented in Java.

Maven pom.xml File

The Maven pom.xml file looks like this:

The spring-jms dependency is used by the test-class that will be implemented below and is not necessary to start the ActiveMQ broker.

ActiveMQ Configuration File

The ActiveMQ configuration file I have used is provided below. Further details on the ActiveMQ XML configuration can be found in the ActiveMQ documentation.
The activemq.xml file is to be located in the src/test/resources directory in the Maven project.

Note the useShutdownHook=”false” attribute in the <broker> element. The ActiveMQ shutdown-hook is disabled in order to avoid an exception when the JMV in which the test(s) has run is shut down.

JUnit Test Class

Finally the JUnit test class is provided as to show that things work as expected and not as a good example on how to implement JUnit tests:

Running the Example

The example can be run by going to a console/terminal window and issuing the following command:

Among a lot of other output, you should see the following in the console:

That’s it for this time. Happy coding!

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *