JBoss.orgCommunity Documentation

HornetQ QuickStart Guide

Putting the buzz in messaging

HornetQ Logo

Copyright © 2010 Red Hat, Inc. and others.

The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA").

An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.

Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.

What is HornetQ?

Why use HornetQ? Here are just a few of the reasons:

  • 100% open source software. HornetQ is licenced using the Apache Software License v2.0 to minimise barriers to adoption.

  • HornetQ is designed with usability in mind.

  • Written in Java. Runs on any platform with a Java 6+ runtime, that's everything from Windows desktops to IBM mainframes.

  • Amazing performance. Our class beating high performance journal provides persistent messaging performance at rates normally seen for non persistent messaging, our non persistent messaging performance rocks the boat too.

  • Full feature set. All the features you'd expect in any serious messaging system, and others you won't find anywhere else.

  • Elegant, clean-cut design with minimal third party dependencies. Run HornetQ stand-alone, run it in integrated in your favourite JEE application server, or run it embedded inside your own product. It's up to you.

  • Seamless high availability. We provide a HA solution with automatic client failover so you can guarantee zero message loss or duplication in event of server failure.

  • Hugely flexible clustering. Create clusters of servers that know how to load balance messages. Link geographically distributed clusters over unreliable connections to form a global network. Configure routing of messages in a highly flexible way.

  • For a full list of features, please see the features wiki page .

This section describes how to install HornetQ.

After downloading the distribution, unzip it into your chosen directory. At this point it should be possible to run straight out of the box, the following describes the directory structure:

         |___ bin
         |___ config
         |      |___ jboss-as-4
         |      |___ jboss-as-5
         |      |___ stand-alone
         |___ docs
         |      |___ api
         |      |___ quickstart-guide
         |      |___ user-manual
         |___ examples
         |      |___ core
         |      |___ javaee
         |      |___ jms
         |___ lib
         |___ licenses
         |___ schemas
  • bin -- binaries and scripts needed to run HornetQ.

  • config -- configuration files needed to configure HornetQ. This contains configurations to run HornetQ either in stand-alone or inside JBoss AS 4 and 5. Please refer to the reference guide for details on configuration.

  • docs -- guides and javadocs for HornetQ

  • examples -- JMS and Java EE examples. Please refer to the 'running examples' chapter for details on how to run them.

  • lib -- jars and libraries needed to run HornetQ

  • licenses -- licenses for HornetQ

  • schemas -- XML Schemas used to validate HornetQ configuration files

HornetQ can also be deployed in JBoss AS 5. It is not currently shipped by default with the application server (it is scheduled to be shipped as default JMS provider in JBoss Application Server 6.0), so you will need to create new AS 5 profiles to run AS 5 with HornetQ.

To create AS 5 profiles:

  1. Download JBoss AS 5

  2. Set the environment property JBOSS_HOME to point to the directory where you installed JBoss AS 5

  3. run ./build.sh (or build.bat if you are on Windows) in HornetQ config/jboss-as-5 directory

This will create 2 new profiles in $JBOSS_HOME/server:

  • default-with-hornetq -- it corresponds to AS 5 default profile with HornetQ as its JMS provider. In this profile, HornetQ is non-clustered

  • all-with-hornetq -- it corresponds to AS 5 all profile with HornetQ as its JMS provider. In this profile, HornetQ is clustered

You can then start JBoss AS 5 using one of these profiles, e.g. :

$JBOSS_HOME/bin/run.sh -c default-with-hornetq

To run HornetQ in JBoss AS 5, you need to create the AS 5 profiles for HornetQ first. Then run JBoss AS 5 with one these profiles. For example, to run JBoss AS 5 with a non-clustered HornetQ server, got to $JBOSS_HOME/bin directory and type:

        bin$ ./run.sh -c default-with-hornetq
        15:18:35,460 INFO  [ServerImpl] Starting JBoss (Microcontainer)...
        15:18:35,462 INFO  [ServerImpl] Release ID: JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=
        JBoss_5_1_0_GA date=200905221053)
        15:19:30,305 INFO  [HornetQServerImpl] HornetQ Server version 
        2.0.0.CR3 (yellowjacket, 111) started
        15:19:43,601 INFO  [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=
        JBoss_5_1_0_GA date=200905221053)]Started in 1m:14s:556ms

In the directory examples there are 2 sets of examples, these are

  • JMS Examples - these demonstrate functionality while sending and consumng JMS messages.

  • Java EE Examples - these demonstrate application server integration, e.g. MDBs, EJBs, Servlets, etc.

The JMS Examples all follow the same format. Each examples is contained in its own directory which contains the following.

Each example will start one or more stand-alone servers and stop them after the example has completed.

As a quick start we'll run the queue example. For all other examples refer to the main user manual.

Firstly open a Shell or a Command prompt and navigate to the examples/jms/queue directory.

Type the command ./build.sh (or build.bat if you are running on Windows), and you should see the following output:

Buildfile: build.xml



     [echo] src.example.dir=/home/andy/projects/hornetq/trunk/examples/jms/queue/src
    [javac] Compiling 5 source files to /home/andy/projects/hornetq/trunk/examples/jms/queue

     [java] 10:41:04,149 INFO  @main [JMSExample] hornetq.example.runServer is true
     [java] 10:41:04,149 INFO  @main [JMSExample] starting server with config 'server0'
 logServerOutput true
     [java] 10:41:04,149 INFO  @main [JMSExample] and vm args: -Xms512M,-Xmx512M,-XX:+U
     [java] org.hornetq.jms.example.SpawnedJMSServer out:10:41:08,437 INFO  @main [Journal
StorageManager] AIO journal selected
     [java] org.hornetq.jms.example.SpawnedJMSServer out:10:41:08,437 WARN  @main [Journal
StorageManager] AIO wasn't located on this platform, it will fall back to using pure Jav
a NIO. If your platform is Linux, install LibAIO to enable the AIO journal
     [java] org.hornetq.jms.example.SpawnedJMSServer out:10:41:08,437 WARN  @main [Securit
yStoreImpl] It has been detected that the cluster admin password which is used to replic
ate management operation from one node to the other has not had its password changed fro
m the installation default. Please see the HornetQ user guide for instructions o
n how to do this.
     [java] org.hornetq.jms.example.SpawnedJMSServer out:10:41:10,941 INFO  @main [HornetQCo
nnectionFactory] read only is false
     [java] org.hornetq.jms.example.SpawnedJMSServer out:10:41:10,941 INFO  @main [HornetQCo
nnectionFactory] read only is false
     [java] org.hornetq.jms.example.SpawnedJMSServer out:10:41:10,941 INFO  @main [HornetQCo
nnectionFactory] read only is false
     [java] org.hornetq.jms.example.SpawnedJMSServer out:10:41:10,991 WARN  @main [JMSServ
erManagerImpl] Binding for java:/ConnectionFactory already exists
     [java] org.hornetq.jms.example.SpawnedJMSServer out:10:41:10,991 WARN  @main [JMSServ
erManagerImpl] Binding for java:/XAConnectionFactory already exists
     [java] org.hornetq.jms.example.SpawnedJMSServer out:10:41:11,241 INFO  @main [Messagi
ngServerImpl] HornetQ Server version 2.0.0.BETA5 (buzz-buzz, 107) started
     [java] org.hornetq.jms.example.SpawnedJMSServer out:10:41:11,241 INFO  @main [HornetQBoot
strapServer] HornetQ server started
     [java] org.hornetq.jms.example.SpawnedJMSServer out:STARTED::
     [java] 10:41:11,276 INFO  @main [JMSExample] using server0/client-jndi.properties f
or jndi
     [java] Sent message: This is a text message
     [java] Received message: This is a text message
     [java] #####################
     [java] ###    SUCCESS!   ###
     [java] #####################

Total time: 13 seconds

Congratulations! You have successfully run your first HornetQ example. Try some of the others.

The Java EE Examples are examples that require a JEE application server to run. They include MDB, Servlet, EJB examples etc. For this you will need the JBoss Application Server installed. How to do this is explained in the previous chapters.

We'll use the MDB example for the purposes of this guide. For the other examples refer to the user guide. Before going any further ensure that the JBoss Application Server is running.

Like the other Java EE examples the MDB example is a JEE Application which first needs deploying in the JBoss Application Server. The first thing we need to do is set the JBOSS_HOME environment property to the location of the JBoss Application Server, in a Linux shell this would be something like:

export JBOSS_HOME=/home/jbossas5.1/build/output/jboss-5.1.0.GA

Once set we can then deploy the application, from inside the examples/javaee/mdb directory run the command:

./build.sh deploy

This will make a copy of the messaging profile in the JBoss Application server and start the server.

In the shell window you should see something like the following output:

Buildfile: build.xml



     [copy] Copying 1 file to /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA
     [copy] Copying 1 file to /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA



      [jar] Building jar: /home/andy/projects/hornetq/trunk/examples/javaee/mdb/build/mdb-exa

      [jar] Building jar: /home/andy/projects/hornetq/trunk/examples/javaee/mdb/build/mdb-exa

     [copy] Copying 1 file to /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA


     [exec] 16:01:04,607 INFO  [JBossASKernel] 	Class:javax.jms.MessageListener
     [exec] 16:01:04,607 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=mdb-example.ear,
     jar=mdb-example.jar,name=MessageMDBExample,service=EJB3) to KernelDeployment of: 
     [exec] 16:01:04,702 INFO  [EJBContainer] STARTED EJB: org.hornetq.javaee.example.server
     .MDBExample ejbName: MessageMDBExample
     [exec] 16:01:09,496 INFO  [TomcatDeployment] deploy, ctxPath=/mdb-example
     [exec] 16:01:09,812 WARNING [config] Unable to process deployment descriptor for cont
     ext '/mdb-example'
     [exec] 16:01:09,812 INFO  [config] Initializing Mojarra (1.2_12-b01-FCS) for context 
     [exec] 16:01:09,958 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-
     [exec] 16:01:09,990 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-
     [exec] 16:01:10,001 INFO  [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag
     =JBoss_5_1_0_GA date=200905151005)] Started in 6m:21s:797ms

We can now run the example, do this by running the following command from within the mdb directory.


You should see some output similar to the following:

Buildfile: build.xml




     [java] Sent message: This is a text message

Total time: 7 seconds

You may also see some output from the JBoss Application Server, in this instance it is:

16:27:54,703 INFO  [STDOUT] message This is a text message received

The application can then be undeployed by running the following command from within the mdb directory.

./build.sh undeploy

This should so some output similar to the following:

Buildfile: build.xml



   [delete] Deleting: /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA
   [delete] Deleting: /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA
   [delete] Deleting: /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA

Total time: 1 second

You can verify that the application has been undeployed by checking the output from the JBoss Application Server, in this instance it will be something like:

16:36:45,277 INFO  [EJBContainer] STOPPED EJB: org.jboss.javaee.example.server.MDBExample 
         ejbName: MessageMDBExample

Congratulations! you have successfully deployed and run a Java EE example.