Book Image

Instant Apache ActiveMQ Messaging Application Development How-to

By : Timothy A. Bish
Book Image

Instant Apache ActiveMQ Messaging Application Development How-to

By: Timothy A. Bish

Overview of this book

Apache ActiveMQ is a powerful and popular open source messaging and Integration Patterns server. ActiveMQ is a fully JMS 1.1 compliant Message Broker and supports many advanced features beyond the JMS specification.Instant ActiveMQ Application Development How-to shows you how to get started with the ActiveMQ Message Broker. You will learn how to develop message-based applications using ActiveMQ and the JMS specification. In this book you will learn all the basic skills you need to start writing Java Messaging applications with a firm grounding in the more advanced features of ActiveMQ, giving you the tools to continue to master application development using ActiveMQ. Starting by applying the messaging features of the JMS specification to write basic messaging applications, you will develop a basic JMS application using topics and queues to broadcast events as well as perform Request and Response operations over the JMS. Once you have mastered the simple tasks you will move onto using the advanced features in ActiveMQ to supercharge your messaging applications. You will get to grips with ActiveMQ's scheduler to delay messages. You will also learn how to leverage ActiveMQ's fault-tolerant capabilities to create robust client applications.
Table of Contents (7 chapters)

Setting up our development environment (Simple)


Now that we have a broker installed and know how to start and stop it, we need to gather together the tools we will need to craft our ActiveMQ applications.

We will be using Apache Maven throughout this book to build and run the examples. Maven is a build management tool that provides a simple way to create Java applications using an XML-based project file called a POM file. You can learn more about Maven by visiting the project website at http://maven.apache.org/index.html.

Getting ready

In order to install Apache Maven, you need to download it from the Maven download page located here: http://maven.apache.org/download.cgi

How to do it...

You install Maven by following these steps:

  1. Download and extract the Maven distribution appropriate for your OS into a permanent location.

  2. Create an environment variable called M2_HOME that references the installation directory you chose in Step 1.

  3. Add the Maven executable to your system path using the M2_HOME/bin location.

You should now be able to check on your Maven installation by opening a terminal and executing the following:

$ mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 12:31:09-0500)
Maven home: /usr/share/maven
Java version: 1.6.0_41, vendor: Apple Inc.

Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.8.2", arch: "x86_64", family: "mac"

You should see output that looks similar to the preceding code. If you don't, you should refer to the Maven instructions instruction located on the download page at http://maven.apache.org/download.cgi.

How it works...

Apache Maven organizes your code into projects that are configured and managed using an XML file named pom.xml. The examples for each recipe in this book are separated into individual Maven projects that make it simple for you to build and run the code without having to set up your own builds.

Note

Keep in mind that Maven requires an Internet connection in order to download the plugins and project dependencies for you from the Maven site. Once you've built and installed the project in your local Maven repo, you can go offline if you need to and still run the project.

Now that you have Maven installed and working, it's a good idea to try and build the samples that we will be using throughout this book to ensure that everything is working as expected and to gain some experience building a Maven project.

Assuming you've already downloaded and extracted the source archive for the sample ActiveMQ applications, open a terminal and change to the samples directory. In the terminal, enter the following command:

$mvn compile

After running this command you'll most likely see a lot of information flowing by in the terminal as Maven downloads the various dependencies for the projects and runs the builds for each. At the end of the build process you should see a message informing you that the build was successful, a truncated sample is shown in the following code:

[INFO] ------------------------------------------------------------------[INFO] Building ActiveMQ-Application-Development-Examples 1.0
[INFO] ------------------------------------------------------------------[INFO] ------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Simple-JMS-Application ......................... SUCCESS [0.630s]
[INFO] JobProducer .................................... SUCCESS [0.014s]
[INFO] JobConsumer .................................... SUCCESS [0.013s]
[INFO] ActiveMQ-Application-Development-Examples ...... SUCCESS [0.000s]
[INFO] ------------------------------------------------------------------[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------[INFO] Total time: 0.780s
[INFO] Finished at: Sun Feb 24 17:37:11 EST 2013
[INFO] Final Memory: 4M/265M
[INFO] ------------------------------------------------------------------

If you don't see a BUILD SUCCESS in your own build, something went wrong and you may need to refer to the troubleshooting information on the Maven website.

There's more...

If you are more comfortable working with code in an integrated development environment (IDE), it's quite simple to use the provided sample applications from most IDEs as long as they have support for Maven projects. Most modern IDEs have built in support for Maven projects and you simply need to import the project into the IDE by following the instructions provided by the IDE documentation. There are many freely available IDEs to choose from if you don't already have one installed; Eclipse is a good choice since it's free, IntelliJ also comes in a free community edition and integrates well with Maven projects.