nativeInstalleractivemq

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, please check the latest version available and the download link from Apache Maven download page and install it following these instructions. Please replace the link with the latest version:

    $ cd $HOME
    $ wget https://www-us.apache.org/dist/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz
    $ 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 installdir/activemq/examples/amqp/java
    
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>2.1</version>
      <configuration>
        <fork>true</fork>       
        <source>1.6</source>
        <target>1.6</target>
      </configuration>
    </plugin>
    
  • 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 127.0.0.1 for running this example:

    $ export ACTIVEMQ_USER=admin
    $ export ACTIVEMQ_PASSWORD=PASSWORD
    $ export ACTIVEMQ_HOST=127.0.0.1
    
  • 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 May 10, 2019