Log inSign up

Set up the ActiveMQ message broker with Java

Install a Java 17 or 21 runtime, unpack the ActiveMQ Classic 6 binary archive into /opt/activemq and start bin/activemq console from a systemd unit as a dedicated user. Then add broker passwords in conf/activemq.xml, replace the default console password, and expose only an SSL transport on port 61617.

Topic: Queues and messaging · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13 · Updated 2026-12-03

Classic or Artemis: which ActiveMQ is this?

This page covers ActiveMQ Classic, the long-running broker line now at version 6, which speaks OpenWire (the native JMS protocol), AMQP 1.0, STOMP and MQTT out of one process. Its sibling, ActiveMQ Artemis, is a separate code base with its own installer (artemis create) and configuration files; pick Artemis when an application asks for it by name, and Classic when existing JMS code or tools such as Camel already expect it.

Version 6 moved to the Jakarta Messaging namespace and needs Java 17 or newer. The broker runs comfortably in a 512 MB to 1 GB heap for modest queues, so 2 GB of RAM is a sensible floor. Work as a sudo user, as set up in the sudo user guide.

How do you install Java and the ActiveMQ archive?

Install the headless JRE, download the binary release with its checksum and unpack it into a directory owned by a service account. Look up the newest 6.x number on the ActiveMQ download page and set it below.

sudo apt update
# Ubuntu 24.04, Ubuntu 22.04 and Debian 13
sudo apt install -y openjdk-21-jre-headless curl
# Debian 12
sudo apt install -y openjdk-17-jre-headless curl
java -version

AV=6.1.8
curl -fLO "https://downloads.apache.org/activemq/$AV/apache-activemq-$AV-bin.tar.gz"
curl -fLO "https://downloads.apache.org/activemq/$AV/apache-activemq-$AV-bin.tar.gz.sha512"
sha512sum apache-activemq-$AV-bin.tar.gz
cat apache-activemq-$AV-bin.tar.gz.sha512
sudo useradd --system --home /opt/activemq --shell /usr/sbin/nologin activemq
sudo mkdir -p /opt/activemq
sudo tar -xzf apache-activemq-$AV-bin.tar.gz -C /opt/activemq --strip-components=1
sudo chown -R activemq:activemq /opt/activemq
ls /opt/activemq/*.jar

The jar name in the last listing carries the installed version. Releases that have rotated off the main mirror stay available under archive.apache.org/dist/activemq/.

How do you run the broker as a service?

Use the console mode, which keeps the JVM in the foreground so systemd can supervise it directly. First size the heap in bin/setenv, where the line starting ACTIVEMQ_OPTS_MEMORY sets the JVM limits.

sudo sed -i 's/^ACTIVEMQ_OPTS_MEMORY=.*/ACTIVEMQ_OPTS_MEMORY="-Xms256M -Xmx768M"/' /opt/activemq/bin/setenv
grep ^ACTIVEMQ_OPTS_MEMORY /opt/activemq/bin/setenv

sudo tee /etc/systemd/system/activemq.service >/dev/null <<'EOF'
[Unit]
Description=Apache ActiveMQ Classic
After=network-online.target
Wants=network-online.target

[Service]
User=activemq
Group=activemq
WorkingDirectory=/opt/activemq
ExecStart=/opt/activemq/bin/activemq console
Restart=on-failure
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now activemq
sudo ss -ltnp | grep java

You should see listeners on 61616 (OpenWire), 5672 (AMQP), 61613 (STOMP), 1883 (MQTT), 61614 (WebSocket) and 8161 on 127.0.0.1 (web console).

How do you require passwords for clients?

Add the simple authentication plugin inside the broker element of /opt/activemq/conf/activemq.xml and give each application its own account. Without it, any client that reaches a transport port may connect.

<plugins>
  <simpleAuthenticationPlugin anonymousAccessAllowed="false">
    <users>
      <authenticationUser username="ops" password="Ops-Long-Secret" groups="admins,users"/>
      <authenticationUser username="billing" password="Billing-Long-Secret" groups="users"/>
    </users>
  </simpleAuthenticationPlugin>
</plugins>

Since the file now holds secrets, run sudo chmod 640 /opt/activemq/conf/activemq.xml. For per-queue rights, add an authorizationPlugin with entries that map destinations to the admins and users groups. Next, change the console login: find which properties file the console reads with grep -n properties /opt/activemq/conf/jetty.xml, then replace the default admin password in that file. Restart with sudo systemctl restart activemq.

How do you trim the ports and add an SSL transport?

Keep only the protocols you use, bind the plain ones to localhost and add an ssl connector for remote clients. Convert a certificate for mq.example.net into a PKCS12 keystore first; issue it with Certbot.

sudo openssl pkcs12 -export -in /etc/letsencrypt/live/mq.example.net/fullchain.pem -inkey /etc/letsencrypt/live/mq.example.net/privkey.pem -name broker -out /opt/activemq/conf/broker.p12 -passout pass:Keystore-Secret
sudo chown activemq:activemq /opt/activemq/conf/broker.p12
sudo chmod 600 /opt/activemq/conf/broker.p12

In activemq.xml, add the SSL context inside broker and replace the transportConnectors block:

<sslContext>
  <sslContext keyStore="file:${activemq.conf}/broker.p12" keyStorePassword="Keystore-Secret" keyStoreType="PKCS12"/>
</sslContext>

<transportConnectors>
  <transportConnector name="openwire" uri="tcp://127.0.0.1:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
  <transportConnector name="ssl" uri="ssl://0.0.0.0:61617?transport.enabledProtocols=TLSv1.2,TLSv1.3"/>
  <transportConnector name="amqp+ssl" uri="amqp+ssl://0.0.0.0:5671"/>
</transportConnectors>

Note the &amp;: inside XML an ampersand in a URI must be written as an entity. Open the firewall for the encrypted ports only:

sudo systemctl restart activemq
sudo ufw allow 22/tcp
sudo ufw allow 61617/tcp
sudo ufw allow 5671/tcp
sudo ufw enable
openssl s_client -connect mq.example.net:61617 -brief </dev/null

How do you send and receive test messages?

The activemq script includes a producer and a consumer, which are enough to prove routing and authentication.

cd /opt/activemq
sudo -u activemq bin/activemq producer --brokerUrl tcp://127.0.0.1:61616 --user billing --password 'Billing-Long-Secret' --destination queue://billing.invoices --messageCount 5
sudo -u activemq bin/activemq consumer --brokerUrl tcp://127.0.0.1:61616 --user billing --password 'Billing-Long-Secret' --destination queue://billing.invoices --messageCount 5
sudo -u activemq bin/activemq dstat queues

The consumer prints five received messages and dstat shows the queue with an enqueue and dequeue count of five. A wrong password produces a SecurityException in the client output, which also confirms the plugin is active.

To look around the web console, open an SSH tunnel and browse to http://localhost:8161/admin:

ssh -L 8161:127.0.0.1:8161 deploy@198.51.100.24

How do you link brokers on different servers?

Create a network connector on one broker that dials the other over SSL with a dedicated account; messages then flow to wherever a consumer is waiting. Our servers talk over public IPs, so restrict 61617 on each broker to its peer when the port is only meant for broker links, or keep application clients and peers on separate connectors.

<networkConnectors>
  <networkConnector name="to-mq2" uri="static:(ssl://mq2.example.net:61617)" userName="bridge" password="Bridge-Long-Secret" duplex="true"/>
</networkConnectors>

# on mq2 (198.51.100.25), accept only mq1 on the broker link port
sudo ufw allow proto tcp from 198.51.100.24 to any port 61617

Add the bridge user to the authentication plugin on both sides. A network of brokers spreads load and survives one node failing for new messages, but stored messages on a dead node wait until it returns; for that case, look at a shared or replicated store, or move to Artemis replication.

How do you upgrade and troubleshoot ActiveMQ?

Upgrade by unpacking the new release into a fresh directory, copying over conf/ and data/, and pointing the systemd unit at it, so you can switch back quickly. Compare your activemq.xml with the new default file for removed options before restarting.

Logs are in /opt/activemq/data/activemq.log and journalctl -u activemq. A broker that stops accepting messages has usually hit a store or memory limit set in systemUsage; raise storeUsage or clean up abandoned queues. When the console says it cannot bind 8161, another process holds the port. Watch the KahaDB directory size with the hints in the disk usage guide, and keep the old ActiveMQ 5.x line only for applications that cannot move to Jakarta clients.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-2single broker for a few queues1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months
A2-4networked broker with larger heap2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months

Questions about Apache ActiveMQ Classic

Which Java version does ActiveMQ Classic 6 need?

Java 17 or newer. Java 21 from the distribution archive works well on Ubuntu 24.04 and Debian 13; see the OpenJDK guide.

Can Python or Node clients use ActiveMQ?

Yes, through STOMP, AMQP 1.0 or MQTT. Enable only the connector they need and protect it with TLS.

Where are messages stored?

In KahaDB under /opt/activemq/data/kahadb. Stop the broker or use your backup routine when copying it.

Is the web console safe to expose?

Keep it on 127.0.0.1 and use an SSH tunnel. If a team needs it, put it behind a reverse proxy with HTTPS and strong passwords.

Why does my client fail with a frame size error?

The message is larger than wireFormat.maxFrameSize on the connector. Raise it, or better, store large payloads elsewhere and send a reference.