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, install it following these instructions:

    • Debian:

      $ sudo apt-get install maven

    • CentOS:

      $ sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo $ sudo yum install apache-maven

  • Next, activate a Maven profile. To do this, modify the Maven settings.xml file (usually located in /etc/maven/settings.xml or /etc/maven2/settings.xml, although the path might differ on your server) and include the following:

    <profiles>
      ...
      <profile>
        <id>env-dev</id>
        <activation>
          <property>
            <name>target-env</name>
            <value>dev</value>
          </property>
        </activation>
        <properties>
          <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
          <maven.compiler.fork>true</maven.compiler.fork>
        </properties>
      </profile>
    </profiles>
    
     <activeProfiles>
      <activeProfile>env-dev</activeProfile>
    </activeProfiles>
    
  • Go to the examples/ folder and install it using maven:

    $ cd installdir/activemq/examples/amqp/java
    $ sudo mvn install
    
  • Export the environment variables you need and run the example. Note that you can obtain your server’s private IP address by using the /sbin/ifconfig command.

    $ export ACTIVEMQ_USER=admin
    $ export ACTIVEMQ_PASSWORD=PASSWORD
    $ export ACTIVEMQ_HOST=localhost
    $ java -cp target/amqp-example-0.1-SNAPSHOT.jar example.Listener &
    $ java -cp target/amqp-example-0.1-SNAPSHOT.jar example.Publisher
    

Execute the Listener and Publisher on different machines. You should now see the example running.