Run an ActiveMQ example

The following steps walk you through running an ActiveMQ example using the Java source code.

  • First, ensure that you have Maven installed on the server. If you don’t, check the latest version available and the download link from Apache Maven download page and install it following these instructions. Replace the link with the latest version:

      $ cd $HOME
      $ wget
      $ tar -xzvf apache-maven*.tar.gz
      $ mv apache-maven-3.6.1 maven
  • Next, go to the examples/amqp/java/ folder and edit the ‘pom.xml’ file. It is required to add “true” into the “maven-compiler-plugin” section:

      $ cd /opt/bitnami/activemq/examples/amqp/java
  • Then install it using maven:

      $ sudo ~/maven/bin/mvn install
  • Export the environment variables you need and run the example. You can open two terminals in the server and run the following commands in both of them. You can use for running this example:

      $ export ACTIVEMQ_USER=admin
      $ export ACTIVEMQ_HOST=
  • Then execute the Listener in one of the consoles.

      $ java -cp target/amqp-example-0.1-SNAPSHOT.jar example.Listener
  • And the Publisher in the other terminal.

      $ java -cp target/amqp-example-0.1-SNAPSHOT.jar example.Publisher

You should now see the example program sending the messages:

Sent 1000 messages
Sent 2000 messages
Sent 3000 messages

And in the other terminal the messages received.

Waiting for messages...
Received 1000 messages.
Received 2000 messages.
Received 3000 messages.
Last modification December 21, 2022