ActiveMQ - Getting Started

Apache ActiveMQ

Share

This is an Apache ActiveMQ getting started tutorial.

What is Apache ActiveMQ?

Apache ActiveMQ is the most popular and powerful open source messaging and Integration Patterns server.

Before we start we will need Java and ActiveMQ installed.

Installing on Unix/Linux/MacOSX/macOS system

Step 1: Install Java SE

Java SE 1.6 or higher is required. Click here to download.

Once you have Java SE installed you can check if it is setup correctly by opening Terminal and typing the following command.

$ java -version

You will see the following output

java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

The output will vary based on the version installed. Important point to note is that Java SE is installed and its version is 1.8 in the above case.

Step 2: Install ActiveMQ

Download and install ActiveMQ from Apache ActiveMQ website. Click here to download. Get the stable release.

For Unix/Linux/Cygwin Distribution download apache-activemq-5.14.3-bin.tar.gz or latest version. After downloading extract the file.

Sample path

/Users/yusufshakeel/Documents/apache-activemq-5.14.3

Optional Step: Install Apache Ant

Apache Ant is a Java library and command-line tool that help building software.

Apache Ant is required if you want to build and test the examples that comes with ActiveMQ. Click here to download.

Apache Ant v1.9.x requires Java5 at runtime. While v1.10.x requires Java8 at runtime.

For Unix/Linux/Mac Distribution download apache-ant-1.10.1-bin.tar.bz2 or latest version. After downloading extract the file.

Sample path

/Users/yusufshakeel/Documents/apache-ant-1.10.1

Lastly, make sure to set up and put the $ANT_HOME environment variable in the $PATH environment variable.

Open terminal and type the following command

$ cd

Now using vi command open .bash_profile

$ vi .bash_profile

Now, inside the file add the following lines. Press I key to get into INSERT mode.

#Apache Ant
export ANT_HOME=/Users/yusufshakeel/Documents/apache-ant-1.10.1

#Export to PATH
export PATH=$ANT_HOME/bin:$PATH

PATH may contain some other values. Be careful when making changes.

Once done press ESC key and type :wq and hit Enter

Now, check if Ant was properly installed by typing the following command in the terminal.

$ ant -version
Apache Ant(TM) version 1.10.1 compiled on February 2 2017

Ant version may version depending on what you have downloaded.

Content of ActiveMQ folder


Important files/directories

activemq-all-5.14.3.jar

This jar file contains all of ActiveMQ.

bin

This directory contains all the binary/executable files.

conf

This directory contains the configuration related files for ActiveMQ.

data

This directory is for storing log files and message data.

example

This directory contains some ActiveMQ examples.

lib

This directory contains all the libraries needed by ActiveMQ.

How to start ActiveMQ?

Move inside the ActiveMQ directory and type the following command.

$ cd /Users/yusufshakeel/Documents/apache-activemq-5.14.3
$ ./bin/activemq console

Output

INFO: Loading '/Users/yusufshakeel/Documents/apache-activemq-5.14.3//bin/env'
INFO: Using java '/usr/bin/java'
INFO: Starting in foreground, this is just for debugging purposes (stop process by pressing CTRL+C)
INFO: Creating pidfile /Users/yusufshakeel/Documents/apache-activemq-5.14.3//data/activemq.pid
Java Runtime: Oracle Corporation 1.8.0_102 /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre
  Heap sizes: current=62976k  free=60026k  max=932352k
    JVM args: -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=/Users/yusufshakeel/Documents/apache-activemq-5.14.3//conf/login.config -Dcom.sun.management.jmxremote -Djava.awt.headless=true -Djava.io.tmpdir=/Users/yusufshakeel/Documents/apache-activemq-5.14.3//tmp -Dactivemq.classpath=/Users/yusufshakeel/Documents/apache-activemq-5.14.3//conf:/Users/yusufshakeel/Documents/apache-activemq-5.14.3//../lib/: -Dactivemq.home=/Users/yusufshakeel/Documents/apache-activemq-5.14.3/ -Dactivemq.base=/Users/yusufshakeel/Documents/apache-activemq-5.14.3/ -Dactivemq.conf=/Users/yusufshakeel/Documents/apache-activemq-5.14.3//conf -Dactivemq.data=/Users/yusufshakeel/Documents/apache-activemq-5.14.3//data
Extensions classpath:
  [/Users/yusufshakeel/Documents/apache-activemq-5.14.3/lib,/Users/yusufshakeel/Documents/apache-activemq-5.14.3/lib/camel,/Users/yusufshakeel/Documents/apache-activemq-5.14.3/lib/optional,/Users/yusufshakeel/Documents/apache-activemq-5.14.3/lib/web,/Users/yusufshakeel/Documents/apache-activemq-5.14.3/lib/extra]
ACTIVEMQ_HOME: /Users/yusufshakeel/Documents/apache-activemq-5.14.3
ACTIVEMQ_BASE: /Users/yusufshakeel/Documents/apache-activemq-5.14.3
ACTIVEMQ_CONF: /Users/yusufshakeel/Documents/apache-activemq-5.14.3/conf
ACTIVEMQ_DATA: /Users/yusufshakeel/Documents/apache-activemq-5.14.3/data
Loading message broker from: xbean:activemq.xml
 INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@28feb3fa: startup date [Tue Feb 14 19:46:22 IST 2017]; root of context hierarchy
 INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[/Users/yusufshakeel/Documents/apache-activemq-5.14.3/data/kahadb]
 INFO | PListStore:[/Users/yusufshakeel/Documents/apache-activemq-5.14.3/data/localhost/tmp_storage] started
 INFO | Apache ActiveMQ 5.14.3 (localhost, ID:YUSUF-MacBook-Pro.local-58262-1487081799213-0:1) is starting
 INFO | Listening for connections at: tcp://YUSUF-MacBook-Pro.local:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600
 INFO | Connector openwire started
 INFO | Listening for connections at: amqp://YUSUF-MacBook-Pro.local:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600
 INFO | Connector amqp started
 INFO | Listening for connections at: stomp://YUSUF-MacBook-Pro.local:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600
 INFO | Connector stomp started
 INFO | Listening for connections at: mqtt://YUSUF-MacBook-Pro.local:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600
 INFO | Connector mqtt started
 WARN | ServletContext@o.e.j.s.ServletContextHandler@3e6f3f28{/,null,STARTING} has uncovered http methods for path: /
 INFO | Listening for connections at ws://YUSUF-MacBook-Pro.local:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600
 INFO | Connector ws started
 INFO | Apache ActiveMQ 5.14.3 (localhost, ID:YUSUF-MacBook-Pro.local-58262-1487081799213-0:1) started
 INFO | For help or more information please see: http://activemq.apache.org
 INFO | No Spring WebApplicationInitializer types detected on classpath
 INFO | ActiveMQ WebConsole available at http://0.0.0.0:8161/
 INFO | ActiveMQ Jolokia REST API available at http://0.0.0.0:8161/api/jolokia/
 INFO | Initializing Spring FrameworkServlet 'dispatcher'
 INFO | No Spring WebApplicationInitializer types detected on classpath
 INFO | jolokia-agent: Using policy access restrictor classpath:/jolokia-access.xml

Checking ActiveMQ status

To check ActiveMQ status we use the following command.

$ ./bin/activemq status
INFO: Loading '/Users/yusufshakeel/Documents/apache-activemq-5.14.3//bin/env'
INFO: Using java '/usr/bin/java'
ActiveMQ is running (pid '17572')

How to stop ActiveMQ?

To stop we use stop or Ctrl+C.

$ ./bin/activemq stop
INFO: Loading '/Users/yusufshakeel/Documents/apache-activemq-5.14.3//bin/env'
INFO: Using java '/usr/bin/java'
INFO: Waiting at least 30 seconds for regular process termination of pid '17572' : 
Java Runtime: Oracle Corporation 1.8.0_102 /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre
  Heap sizes: current=62976k  free=61992k  max=932352k
    JVM args: -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=/Users/yusufshakeel/Documents/apache-activemq-5.14.3//conf/login.config -Dactivemq.classpath=/Users/yusufshakeel/Documents/apache-activemq-5.14.3//conf:/Users/yusufshakeel/Documents/apache-activemq-5.14.3//../lib/: -Dactivemq.home=/Users/yusufshakeel/Documents/apache-activemq-5.14.3/ -Dactivemq.base=/Users/yusufshakeel/Documents/apache-activemq-5.14.3/ -Dactivemq.conf=/Users/yusufshakeel/Documents/apache-activemq-5.14.3//conf -Dactivemq.data=/Users/yusufshakeel/Documents/apache-activemq-5.14.3//data
Extensions classpath:
  [/Users/yusufshakeel/Documents/apache-activemq-5.14.3/lib,/Users/yusufshakeel/Documents/apache-activemq-5.14.3/lib/camel,/Users/yusufshakeel/Documents/apache-activemq-5.14.3/lib/optional,/Users/yusufshakeel/Documents/apache-activemq-5.14.3/lib/web,/Users/yusufshakeel/Documents/apache-activemq-5.14.3/lib/extra]
ACTIVEMQ_HOME: /Users/yusufshakeel/Documents/apache-activemq-5.14.3
ACTIVEMQ_BASE: /Users/yusufshakeel/Documents/apache-activemq-5.14.3
ACTIVEMQ_CONF: /Users/yusufshakeel/Documents/apache-activemq-5.14.3/conf
ACTIVEMQ_DATA: /Users/yusufshakeel/Documents/apache-activemq-5.14.3/data
Connecting to pid: 17572
.....Stopping broker: localhost
.. TERMINATED

Check Web Console

Once the ActiveMQ starts we can access it via web.

On your localhost simply type the following URL in the web browser.

http://localhost:8161/admin

On server type your domain name followed by :8161/admin.

http://www.example.com:8161/admin

When asked for username and password type admin for both the fields. If successful then the following page will open.



Secure Web Console

The default username and password for ActiveMQ web console is admin/admin. To change this perform the following steps.

Step 1: Set authenticate = true

Open the jetty.xml file which is inside the conf directory.

Find the following line.

<!-- set authenticate=false to disable login -->
<property name="authenticate" value="true" />

To turn on login set the value to true. To disable login set it to false.

Step 2: Set username/password

Open jetty-realm.properties file inside the conf directory.

Change/add username and password in the following format username: password [,rolename ...].

Lets say we want to change the username/password to adminuser/root1234 then, we make the following changes.

# is for comment.

## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements.  See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License.  You may obtain a copy of the License at
## 
## http://www.apache.org/licenses/LICENSE-2.0
## 
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------

# Defines users that can access the web (console, demo, etc.)
# username: password [,rolename ...]
#admin: admin, admin
#user: user, user
adminuser: root1234, admin

Now we can login using the new username/password.

Share

Recently Added