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
- 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.
- 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.
- 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.
- 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
- git clone https://github.com/liuzy163/activemq-server.git
- change your working directory into activemq-server
- gradle build
- find the executable jar file from activemq-server/build/libs/activemq-server-1.0.jar
- java -Dserver.port=9988 -jar activemq-server-1.0.jar
Now you have a running activemq broker listening tcp port 61616.