Install Apache ActiveMQ on Ubuntu 18.04

0
83

On an enterprise server, many important applications are likely to cohabit. The need for a broker makes more sense if these applications are constantly transferring information. In addition, an organization’s scalable infrastructure depends on the quality of the applications. Therefore, in this post, I will show you how to install Apache ActiveMQ on Ubuntu 18.04.

In computing, the term broker defines an intermediary between two or more applications that need resources and information between them. So, Apache ActiveMQ is the most popular and powerful open source messaging and Integration Patterns server. It is open source licensed under the Apache 2.0 License.

Besides being able to be used in Java, ActiveMQ can also be used in .NET, C/C++ or Delphi or from script languages such as Perl, Python, PHP, and Ruby through various “cross-language clients”.

So, let us start.

1. Install Java

If you use Ubuntu 18.04 it is unlikely that you do not have Java installed, however, you can do it in an easy way with the following command:

:~$ sudo apt install openjdk-11-jre
1.- Install java
1.- Install java

Next, check the java version to ensure that everything is Ok.

:~$ java -version
2.- java version
2.- java version

This first step is vital because Apache ActiveMQ requires Java to work. That’s why we had to install it.

2. Install Apache ActiveMQ

Now we can continue with the installation. The best way to install Apache ActiveMQ is through your binaries that we can get from your website. With this, you guarantee that you will have the latest stable version available.

First, download the file.

:~$ cd /opt/
:~$ sudo wget http://archive.apache.org/dist/activemq/5.15.8/apache-activemq-5.15.8-bin.tar.gz
3.- Download Apache ActiveMQ
3.- Download Apache ActiveMQ

Decompress it.

:~$ sudo tar xzvf apache-activemq-5.15.8-bin.tar.gz
4.- Decompress the file
4.- Decompress the file

Then, create a symbolic link to make easier the access.

:~$ sudo ln -s apache-activemq-5.15.8 activemq

3. Configure Apache ActiveMQ

First of all, it is necessary to create a systemd service in order to access the program even more easily. To do this, run:

:~$ sudo nano /etc/systemd/system/activemq.service

And add the following:

[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
5.- Creating a systemd service
5.- Creating a systemd service

Now, reload the systemd cache.

:~$ sudo systemctl daemon-reload

NOTE: It is not mandatory to create the file to transform ActiveMQ into a systemd service and in some cases, it can cause problems.

You can also start ActiveMQ with this command:

:~$ /opt/activemq/bin/activemq start

Or stop it with this command:

:~$ /opt/activemq/bin/activemq stop
6.- Start and stop the ActiveMQ program
6.- Start and stop the ActiveMQ program

Next, let us configure it.

Open the activem.xml file. This file contains all ActiveMQ settings.

:~$ sudo nano /opt/activemq/conf/activemq.xml
7.- The config file
7.- The config file

Creating a transport connector

The first step is to configure the transport connector. Edit the file in question and place it in the transport connector section.

It’s a pretty large file, but with the help of nano, we can quickly find the sections. Press CTRL + W and type “transport”.

8.-Config file
8.-Config file

The syntax is very simple:

  • broker_name: is the brokerName attribute of the tag broker of activemq.xml
  • transportOptions: different communication options.

Now, the parameters URI is the in the connection type function. For example, you can specify a broker using TCP or VM.

Let us see an example:

<transportConnection name="openwire" uri="tcp://192.168.3.4:8765?trace=false&soTimeout=60000">

On the URI option, you have to add the protocol, the port, and the options.

9.- Creating a transport connector
9.- Creating a transport connector

System usage

It is also possible to limit the use of system resources. In the same file in the system usage section, you can configure it.

10.- System usage
10.- System usage

There you can limit, for example, the use of the hard disk and the RAM memory.

Finals settings

These are basic ActiveMQ configurations. One thing you can do is prevent the storage buffer from ending up with all the RAM. For that, in the same configuration file go to the policy entry section.

You can limit all the messages to a specific size.

11.- Limit the messages
11.- Limit the messages

Other thing ActiveMQ has a built-in database manager called KahaDB that is mainly in charge of storing messages. You can replace it with MySQL or MariaDB but KahaDB is very superior in performance, so it is not recommended to do this.

Finally, start ActiveMQ. Then, open your web browser and go to http://SERVER_IP:8161.

:~$ /opt/activemq/bin/activemq start
12.- ActiveMQ web interface
12.- ActiveMQ web interface

Conclusion

It is clear that ActiveMQ is an enterprise infrastructure software. Known and very popular for being efficient and a benchmark in its area.

Please share this post with your friends.

LEAVE A REPLY

Please enter your comment!
Please enter your name here