JBoss HornetQ simple tutorial
HornetQ is an open source project to build a multi-protocol, embeddable, very high performance, clustered, asynchronous messaging system.
Why learning another messaging system ? here are a few good reasons:
It takes just a few minutes to be operative, let's start:
http://www.jboss.org/hornetq/downloads.html
Download the latest stable release and unzip in a convenient location.
Launching HornetQ as standalone server is fairly trivial: reach the "bin" folder in your HornetQ distribution and launch run.bat/run.sh

The only requirement is to set the JBOSS_HOME environment variable.

This will create two additional JBoss configurations default-with-hornetq and all-with-hornetq. The former can be used to run JBoss as standalone server and the latter as clustered node.

Now launch JBoss AS using the -c parameter. For example:
run -c default-with-hornetq
An example of how to start an embedded HornetQ server is provided in HornetQExample.java file which can be found in the HORNETQ_HOME/examples/common/src/org/hornetq/common/example
The configuration of HornetQ is split in several files. The following table resumes the basics of its configuration.
As a developer you are likely to be interested to uodate the hornetq-jms.xml file to add/remove new Queue/Topics.
Deploying an MDB is fairly trivial. The only difference with a MDB powered by another JMS provider is the @ResourceAdapter annotation which informs the EJB container to use HornetQ resource adapter configuration.
Why learning another messaging system ? here are a few good reasons:
- Hornet Q is an open source messaging system which can be used as standalone or on any application server or even embedded in your applications.
- HornetQ delivers amazing messaging performance.
- HornetQ provides seamless clustering capabilities.
- Most important for us: it's the default Messaging system in JBoss AS 6.
It takes just a few minutes to be operative, let's start:
http://www.jboss.org/hornetq/downloads.html
Download the latest stable release and unzip in a convenient location.
Start HornetQ
HornetQ can be started in 3 ways:- Standalone server
- Inside an application server
- Embedded in your applications
#1 Standalone server
Launching HornetQ as standalone server is fairly trivial: reach the "bin" folder in your HornetQ distribution and launch run.bat/run.sh

#2 Inside JBoss AS 4.x-5.x-6.x
If you don't want to run HornetQ as standalone but embedded in jBoss AS there's a simple script in the folder HORNETQ-HOME\config\jboss-as named build.bat/build.sh.The only requirement is to set the JBOSS_HOME environment variable.

This will create two additional JBoss configurations default-with-hornetq and all-with-hornetq. The former can be used to run JBoss as standalone server and the latter as clustered node.

Now launch JBoss AS using the -c parameter. For example:
run -c default-with-hornetq
#3 Embedded in your Java code
HornetQ can be started as well in embedded mode. This can be particularly useful for testing purposes if you don't want to start/stop manually the server on your machine.An example of how to start an embedded HornetQ server is provided in HornetQExample.java file which can be found in the HORNETQ_HOME/examples/common/src/org/hornetq/common/example
The configuration of HornetQ is split in several files. The following table resumes the basics of its configuration.
| File | Content |
| hornetq-jboss-beans.xml | Micro container configuration file. |
| hornetq-configuration.xml | Main configuration file. Used to change JMS Storage directories and Message settings. |
| hornetq-jms.xml | JMS Queue/Topic configuration. |
| jms-ds.xml | JMS Provider configuration and Connection factory configuration. |
| login-config.xml | The XML based JAAS login configuration. |
Deploying an MDB is fairly trivial. The only difference with a MDB powered by another JMS provider is the @ResourceAdapter annotation which informs the EJB container to use HornetQ resource adapter configuration.
Ok. In order to test this MDB you have to update your hornetq-jms.xml file (which is located, if you are running HornetQ inside JBoss in deploy\hornetq.sar) by adding the testQueue definition:
And finally here's a generic test client which can be used to send messages to the "testQueue":
Your example is completed. Remeber to add HornetQ libraries into your build path as shown here:


