Published on May 24 2023 in ActiveMQ Java

See how to run ActiveMQ in a cPanel account with private JVM.

ActiveMQ is a popular open-source message broker that is used to send and receive messages between different applications. If you are using a shared hosting account and want to run ActiveMQ, you can follow the steps outlined below.

Firstly, you need to download an ActiveMQ tarball from the official Apache website. For example, you can download a preferred version of ActiveMQ from https://archive.apache.org/dist/activemq/5.16.6/apache-activemq-5.16.6-bin.tar.gz. You should also ensure that your JDK version is high enough to support the version of ActiveMQ you are downloading. The version we are downloading still runs on JDK 8+.

Once you have downloaded the tarball, you should unpack it using the following command:

tar xzf apache-activemq-5.16.6-bin.tar.gz

This will create a new directory called apache-activemq-5.16.6. We can create a symbolic link to make it easier to work with:

ln -s apache-activemq-5.16.6 amq

Next, you need to get custom port assignments for ActiveMQ. Since you are on a shared server, you cannot use arbitrary ports. For example, you may need one port for the ActiveMQ console and five for ActiveMQ services. Let’s assume you were given the ports 10024-10029.

Now you need to update the ActiveMQ configuration file to use these custom ports. You can use the following commands:

sed -ri 's|(tcp://0.0.0.0):61616(\?)|\1:10024\2|' ~/amq/conf/activemq.xml
sed -ri 's|(amqp://0.0.0.0):5672(\?)|\1:10025\2|' ~/amq/conf/activemq.xml
sed -ri 's|(stomp://0.0.0.0):61613(\?)|\1:10026\2|' ~/amq/conf/activemq.xml
sed -ri 's|(mqtt://0.0.0.0):1883(\?)|\1:10027\2|' ~/amq/conf/activemq.xml
sed -ri 's|(ws://0.0.0.0):61614(\?)|\1:10028\2|' ~/amq/conf/activemq.xml

These commands replace the default port numbers in the activemq.xml configuration file with the custom port numbers you were given.

You also need to update the ActiveMQ console port and host using the following commands:

sed -ri 's|(property name="host" value=)"127.0.0.1"|\1"0.0.0.0"|' ~/amq/conf/jetty.xml
sed -ri 's|(property name="port" value=)"8161"|\1"10029"|' ~/amq/conf/jetty.xml

These commands change the console host from 127.0.0.1 to 0.0.0.0 and the console port from 8161 to 10029.

Alternatively, you can use Java startup parameters by adding -Djetty.host=0.0.0.0 -Djetty.port=10029 to ACTIVEMQ_OPTS in ~/amq/bin/env.

Finally, you can start ActiveMQ with the following commands:

cd ~/amq/bin
export ACTIVEMQ_OPTS_MEMORY="-X

Before starting ActiveMQ, you need to set memory limits based on your hosting plan. You can do this by setting the ACTIVEMQ_OPTS_MEMORY environment variable to specify the minimum and maximum heap sizes. For example, if your hosting plan allows up to 128MB of memory, you can set the memory limit as follows:

export ACTIVEMQ_OPTS_MEMORY="-Xms64M -Xmx128M"

This sets the minimum heap size to 64MB and the maximum heap size to 128MB. You can adjust these values based on your hosting plan. If you still need to run another JVM (e.g. with Tomcat) in parallel please order ‘Additional JVM’ addon.

After setting the memory limits, you can start ActiveMQ by running the following command from the ~/amq/bin directory:

./activemq console

This starts ActiveMQ in the foreground and shows the logs on the console. Alternatively, you can start ActiveMQ in the background using the following command:

./activemq start

This starts ActiveMQ in the background and logs the output to the ~/amq/data/activemq.log file.

To stop ActiveMQ, you can run the following command from the ~/amq/bin directory:

./activemq stop

This stops ActiveMQ and releases all resources.

In summary, to run ActiveMQ in a shared hosting account, you need to download and unpack the ActiveMQ tarball, update the configuration files to use custom ports, set memory limits based on your hosting plan, and start ActiveMQ using the ./activemq command.