# Sending JMS messages from a Stateless Clustered Session Bean

$Revision: 2751 $

## Overview

This example deploys in a cluster a stateless session bean that can then send and receive messages from a queue. This is a very simple example that demonstrates using JBoss Messaging in a clustered environment. The client uses HA-JNDI to look up the session bean. It then invokes the session bean to send a message to a test queue and afterwards consumes the same message.

This example relies on having access to a running JBoss Messaging cluster. The JBoss Messaging cluster must be installed and started according to the "JBoss Messaging Clustered Installation" chapter from the release documentation. However, the example will automatically deploy its own queue, unless a queue with the same name is already deployed.

This example also relies on having access to `jboss-messaging-client.jar` archive that comes with the release bundle. If you run this example from an unzipped installation bundle, the example run script is correctly configured to find the client jar. Otherwise, you must modify example's `build.xml` accordingly.

## Running the example

1. Set up the JBOSS_HOME environment variable to point to the JBoss instance you deployed JBoss Messaging into. For example, if you deployed JBoss Messaging in `C:\jboss-4.2.0.GA\server\messaging-node0\deploy`, then your JBOSS_HOME value should be `C:\jboss-4.2.0.GA`.

2. Go to the example's home directory

>     cd ...\examples\stateless

3. Run the example:

>     ant

The output of a successful run should be similar to:

>     $ ant
>     Buildfile: build.xml

>     identify:
>          [echo] ###########################################################################
>          [echo] #         Running the STATELESS CLUSTERED SESSION BEAN example            #
>          [echo] ###########################################################################
>          [echo] The queue:      testFarmQueue
>          [echo] The client jar: ../../../output/lib/jboss-messaging-client.jar

>     sanity-check:

>     init:
>         [mkdir] Created dir: C:\java\messaging\docs\examples\stateless-clustered\output\classes\META-INF
>         [mkdir] Created dir: C:\java\messaging\docs\examples\stateless-clustered\output\lib

>     compile:
>         [javac] Compiling 4 source files to C:\java\messaging\docs\examples\stateless-clustered\output\classes
>         [javac] Note: C:\java\messaging\docs\examples\stateless-clustered\src\org\jboss\example\jms\statelessclustered\bean\StatelessClusteredSessionExampleBean.java uses unchecked or unsafe operations.
>         [javac] Note: Recompile with -Xlint:unchecked for details.

>     jar:
>          [copy] Copying 2 files to C:\java\messaging\docs\examples\stateless-clustered\output\classes\META-INF
>           [jar] Building jar: C:\java\messaging\docs\examples\stateless-clustered\output\lib\stateless-clustered-example.jar

>     deploy:
>          [copy] Copying 1 file to C:\jboss-4.2.0.GA\server\messaging-node0\farm
>          [copy] Copying 1 file to C:\jboss-4.2.0.GA\server\messaging-node0\farm

>     sleep:
>          [echo] Sleeping for 15 seconds ...

>     run:

>     send-and-receive:
>          [java] The Hello! message was successfully sent to the /queue/testFarmQueue queue
>          [java] Queue browse result: 1
>          [java] blocking to receive message from queue /queue/testFarmQueue ...
>          [java] Message Hello! received
>          [java]
>          [java] #####################
>          [java] ###    SUCCESS!   ###
>          [java] #####################

>     undeploy:
>        [delete] Deleting: C:\jboss-4.2.0.GA\server\messaging-node0\farm\stateless-clustered-example.jar
>        [delete] Deleting: C:\jboss-4.2.0.GA\server\messaging-node0\farm\destinations-farm-service.xml

>     BUILD SUCCESSFUL
>     Total time: 19 seconds

## Troublesooting

### 1. I get `"javax.jms.JMSSecurityException: User null is NOT authenticated"`

You probably didn't install JBoss Messaging correctly. A fresh JBoss Messaging installation requires changes in the security configuration of the JBoss instance, specifically a properly configured "`messaging`" security domain. Follow the instructions from the "Installation" paragraph of the release documentation.