Use SpringBoot to Deploy ActiveMQ Broker to Tomcat 1/3

This topic has three parts. Also See part2 in next post and part3.

ActiveMQ can be installed as a standalone server, or it can run within other containers, such as Spring or web containers. When deploying in Tomcat, you have the options of deploying a war file to a standalone Tomcat or using the embedded container provided by SpringBoot.

VM Based Broker in SpringBoot

If a VM based broker is good enough for you (when prototyping or integration testing), you can easily get it up running in minutes. Please see the ActiveMQ SpringBoot example as your start point.

Fully Configurable Broker

If you need a broker with full controllability, you can follow this post here. This post uses Gradle for build. Please see the source code in GitHub. Or you can download the commit by clicking here.

  1. Dependency.  In this example, we selectively choose a few basic individual activemq artifacts instead of using the SpringBoot ActiveMQ starter. Note that there is a activemq-all artifact available, but you may end up in logback conflict with SpringBoot. Since activemq-all artifact is generated by Maven shade plugin, it is hard to exclude logback from activemq-all. So this post uses individual jars. If you need to support other functionalities, please reference to activemq-all pom file.
  2. ActiveMQ configuration is provided by activemq.xml. Here you have all the flexibility to configure your broker. Alternative to the XML based configuration, you can in fact create a BrokerService bean and configure it programmatically in Java.
  3. The ActiveMQ broker is managed by Spring context defined in my-beans.xml, which is exposed to the SpringBoot by annotation @ImportResource(“classpath:my-beans.xml”) in the ActiveMqApplication.java class.
  4. application.properties provides variables that you can change value without changing code. You can also pass in different values when you start your program.

Build and Run

Assume you already have gradle installed, then

  1. git clone https://github.com/liuzy163/activemq-server.git
  2. change your working directory into activemq-server
  3. gradle build
  4. find the executable jar file from activemq-server/build/libs/activemq-server-1.0.jar
  5. java -Dserver.port=9988 -jar activemq-server-1.0.jar

Now you have a running activemq broker listening tcp port 61616.

Advertisements
This entry was posted in Java and tagged , , , , . Bookmark the permalink.

2 Responses to Use SpringBoot to Deploy ActiveMQ Broker to Tomcat 1/3

  1. Pingback: Use SpringBoot to Deploy ActiveMQ Broker to Tomcat-2/2 | SW Notes

  2. Pingback: Use SpringBoot to Deploy ActiveMQ Broker to Tomcat 3/3 | SW Notes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s