How to Install Apache ActiveMQ on Ubuntu 20.04

Apache ActiveMQ is an open-source message broker written in Java. It supports several cross-language clients and protocols.

The Apache ActiveMQ message broker is a fast, reliable, scalable, and totally integrated open source messaging platform for handling lots of messages (ingest) or lots of consumers (dispatch). It uses memory as the storage format; it can be configured to store data persistently on a disk if necessary. The initial startup time can be slow due to the fact that ActiveMQ will load all historical information into memory. However, after the first startup period, which could take up to several minutes depending on how much history you have stored in your queues and other configuration settings, performance starts to scale well up until a point when we consider other factors such as system resources.

Based on its origins as an experience of just moving from an in-house messaging solution to a commercial product, ActiveMQ can be considered as one of those products that have been constantly developed and improved, offering extremely high quality and solid stability.

ActiveMQ provides both a simple embedded broker and a fully deployed, highly available enterprise solution. Its most important features and strengths are high availability and failover (a setup with one broker can survive up to 99.999% of message loss), support for many ways of connecting clients (including web consoles, command-line tools, and libraries, JMS client libraries, etc.), clustering across physical boundaries, load balancing through multiple internal queues per topic, flexible configuration such as persistent or non-persistent messages according to the need, the persistence of data by file or database, security implementation based on JAAS authentication model which also supports LDAP implementation.

ActiveMQ is truly the preferred messaging solution for Java developers, infrastructure architects, and system integrators. It can be used in both small deployments (in which case you will probably use the embedded broker) or big enterprise solutions (which require clustering and failover).

Depending on your needs, ActiveMQ can be easily scaled out to real high availability scenarios with full load balancing across all brokers, including dynamic addition of new nodes when existing ones go down; stateful failover with automatic re-sync and potential data loss (which is always possible), fully supported by ActiveMQ itself: just another two nodes that need to be configured into a cluster for high availability.

Apache ActiveMQ is cross-platform and runs in a Java Virtual Machine (JVM). You could use ActiveMQ on either Linux, Windows, or OS X.

In this guide, we will walk you through the basic installation and setup of Apache ActiveMQ on an Ubuntu 20.04 LTS, as well as run through a basic configuration and verification test.

Let’s get started!

Prerequisites

In order to tie in with our guide, you will need:

  • An Ubuntu Linux box to run ActiveMQ. This could be a physical server or a virtual machine; what matters is that it can run the JVM and has at least 2GB of RAM and 20GB disk space. You should allocate more than that depending on your needs, such as running other services such as ActiveMQ benchmarks, database servers or logging tools.
  • Root access to the running Ubuntu box.

Updating the System

It’s important to make sure the system is up-to-date before installing any packages. Run the following command to update the system.

sudo apt update && sudo apt upgrade -y

You can also install some extra tools that you’ll need for this tutorial using the following commands.

sudo apt install wget curl ia32-libs -y

Installing Java

Apache ActiveMQ is written in Java and therefore requires a Java run-time environment (JRE) to be installed on the machine. You can install it using the following command.

sudo apt install openjdk-11-jre -y

When the installation completes, run the java command with the -version flag to check whether it’s working properly.

java -version

The output should be similar to the following.

Check Java version

Installing Apache ActiveMQ

Now that we have a running system and the JRE environment, we can proceed to download and install Apache ActiveMQ.

First, you will need to download the latest release from ActiveMQ’s official website.

We want the tarball labeled as apache-activemq-5.16.3-bin.tar.gz, the latest version at the time of writing this article.

Run the wget command to download it.

wget http://archive.apache.org/dist/activemq/5.16.3/apache-activemq-5.16.3-bin.tar.gz

Since you are downloading an archive, extract the files using the following command. This should extract the contents into a directory called “apache-activemq-,” and it’s this that we will install ActiveMQ into our system.

sudo tar -xvzf apache-activemq-5.16.3-bin.tar.gz

Next, create a new directory named /opt/activemq and then move all files from apache-activemq into that directory by running the command below

sudo mkdir /opt/activemq && sudo mv apache-activemq-5.16.3/* /opt/activemq

After that, create dedicated user and group accounts to run ActiveMQ. We recommend creating a dedicated user for this purpose, but you can make any changes to the system that you feel are necessary.

Create the required group accounts and user accounts via the following commands.

sudo addgroup --quiet --system activemq
sudo adduser --quiet --system --ingroup activemq --no-create-home --disabled-password activemq

You may need to use sudo chown -R <user>:<group> /opt/activemq if you are not the root user and do not have write permissions to the /opt/ directory. This will change the owner and group of all files in that directory to your username and your primary group respectively.

sudo chown -R activemq:activemq /opt/activemq

Next, you will need to create an Apache ActiveMQ Systemd service unit file by running the following command. Because this provides a means of easily starting, stopping and restarting the service without having to manually go into the directory each time.

sudo nano /etc/systemd/system/activemq.service

Nano will open up an editor window in your terminal session with the file contents empty for you to edit. Enter the following configuration in nano. Replace activemq with your username when you set the JAVA_HOME property.

[Unit]
Description=Apache ActiveMQ
After=network.target

[Service]
Type=forking
User=activemq
Group=activemq
ExecStart=/opt/activemq/bin/activemq start
ExecStop=/opt/activemq/bin/activemq stop

[Install]
WantedBy=multi-user.target

Once done, press CTRL+X, Y, and Enter to save the file.

Then reload the system daemon and start the service by running the following command.

sudo systemctl daemon-reload && sudo systemctl start activemq
sudo systemctl enable activemq

You can check whether or not the service is running properly by using this command to check its status.

sudo systemctl status activemq

The output should show something similar to the following when it’s running properly.

ActiveMQ Systemd service status

Accessing Apache ActiveMQ Web UI

Now that we have the service up and running, we can access it conveniently by using a web browser. Open your favorite browser and go to http://server_ip:8161/admin.

Where server_ip is the actual IP address of your server. By default, ActiveMQ installs a web UI on port 8161 and /admin is for accessing the management console.

You will be directed to a password prompt that asks you to enter a username and password, as shown below.

ActiveMQ Login

Enter the default username and password, which is “admin”, for both fields and click on Sign in. Once logged in, you will land on the Apache ActiveMQ management console, as shown below.

ActiveMQ Dashboard

That’s it! We now have successfully installed Apache ActiveMQ on our Ubuntu 20.04 server with Daemon, Web UI, and Systemd service.

Conclusion

Well, that’s it for this tutorial. We have successfully installed Apache ActiveMQ in our Ubuntu 20.04 server.

You can now make use of Apache ActiveMQ to create a lightweight enterprise messaging system for high-volume message delivery.