Sending JMS messages from a Stateless Session Bean

$Revision: 2751 $

Overview


This example deploys a stateless session bean that then sends and receives messages from a queue. This is a very simple example that demonstrates using JBoss Messaging in a managed environment. The session bean sends a message to a test queue and then pulls the message from the queue using a different connection. The example is considered successful if the message is received correctly.

This example relies on having access to a running JBoss Messaging instance. The JBoss Messaging instance must be installed and started according to the "Installation" paragraph 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\default\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] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     [echo] X              Running the STATELESS SESSION BEAN example                 X
     [echo] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     [echo] The queue: testQueue

sanity-check:

init:
    [mkdir] Created dir: C:\work\src\cvs\jboss-head\jms\docs\examples\stateless\output\classes\META-INF
    [mkdir] Created dir: C:\work\src\cvs\jboss-head\jms\docs\examples\stateless\output\lib

compile:
    [javac] Compiling 4 source files to C:\work\src\cvs\jboss-head\jms\docs\examples\stateless\output\classes

jar:
     [copy] Copying 2 files to C:\work\src\cvs\jboss-head\jms\docs\examples\stateless\output\classes\META-INF
      [jar] Building jar: C:\work\src\cvs\jboss-head\jms\docs\examples\stateless\output\lib\stateless-example.jar

deploy:
     [copy] Copying 1 file to C:\work\src\jboss-4.2.0.GA\build\output\jboss-4.0.3SP1\server\messaging\deploy

sleep:
     [echo] Sleeping for 5 seconds ...

run:

send-and-receive:
     [java] The Hello! message was successfully sent to the /queue/testQueue queue
     [java] Queue browse result: Hello!
     [java] Received Hello!

     [java] #####################
     [java] ###    SUCCESS!   ###
     [java] #####################

undeploy:
   [delete] Deleting: C:\work\src\jboss-4.2.0.GA\build\output\jboss-4.0.3SP1\server\messaging\deploy\stateless-example.jar

BUILD SUCCESSFUL
Total time: 9 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 a default JBoss instance, specifically a properly configured "messaging" security domain.  Follow the instructions from the "Installation" paragraph of the release documentation.