JBoss Messaging EJB3 Message Driven Bean Example

$Revision: 1459 $

Overview


This example deploys a simple EJB3 Message Driven Bean that processes messages sent to a test queue.  Once it receives a message and "processes" it, the EJB3 MDB sends an acknowledgment message to a  temporary destination created by the sender for this purpose. The example is considered  successful if the sender receives the acknowledgment message.

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. 

The example was designed to deploy its server-side artifacts under a JBoss' messaging configuration. If you intend to use the script with a JBoss configuration that is named differently, please modify the example's build.xml accordingly.

Important! The JBoss instance that runs the Messaging server must also have EJB3 support previously installed. If the EJB3 support is not installed, the example will fail with an error message similar to:




C:\work\src\cvs\jboss-head\jms\docs\examples\ejb3mdb\build.xml:60: EJB3 does not seem to be installed in C:\work\src\jboss-4.0.3-src\build\output\jboss-4.0.3/server/messaging!
Install it and try again.
 



For instructions on how to install EJB3 support, please go to http://docs.jboss.org/ejb3/ or use the JBoss Installer.

Note: The current example was tested with the EJB3 release bundled with JBoss 4.0.5. Earlier EJB3 versions may use slightly different APIs that may break the example. If this is the case, please modify the example accordingly. Most likely, you will only need to modify the import fully qualified class names.

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.0.3SP1\server\default\deploy, then your JBOSS_HOME value should be C:\jboss-4.0.3SP1.


2. Go to the example's home directory

cd ...\examples\ejb3mdb

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 EJB3 MDB example                        X
     [echo] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     [echo] The queue: testQueue

sanity-check:

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

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

jar:
      [jar] Building jar: C:\work\src\cvs\jboss-head\jms\docs\examples\ejb3mdb\output\lib\mdb-example.ejb3

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

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

run:

send:
     [java] Queue /queue/testQueue exists
     [java] The Hello! message was successfully sent to the testQueue queue
     [java] Received message: !olleH
     [java] The example connected to JBoss Messaging version 1.0.1.GA (1.0)

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

undeploy:
   [delete] Deleting: C:\work\src\jboss-4.0.3SP1-src\build\output\jboss-4.0.3SP1\server\messaging\deploy\mdb-example.ejb3

BUILD SUCCESSFUL
Total time: 10 seconds


Troublesooting


1. While compiling the example I get

C:\work\src\cvs\jboss-head\jms\docs\examples\ejb3mdb\src\org\jboss\examples\jms\ejb3mdb\EJB3MDBExample.java:29: illegal character: \64
@MessageDriven(activateConfig =
^

You're compiling with Java 4. You need to use Java 5 in order to be able to compile and take advantage of annotations.

2. 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.

3. The example fails with "Have not received any reply. The example failed!" and the server log contains ClassNotFoundExceptions

If all you get after running the example is

send:
     [java] Queue /queue/testQueue exists
     [java] The Hello! message was successfully sent to the
testQueue queue
     [java] java.lang.Exception: Have not received any reply. The example failed!
     [java]     at org.jboss.example.jms.mdb.Sender.example(Sender.java:102)
     [java]     at org.jboss.example.jms.common.ExampleSupport.run(ExampleSupport.java:58)
     [java]     at org.jboss.example.jms.mdb.Sender.main(Sender.java:131)

     [java] #####################
     [java] ###    FAILURE!   ###
     [java] #####################


check the server log. The presence of

2006-04-11 17:14:58,370 DEBUG [org.jboss.ejb.plugins.jms.DLQHandler] Initialization failed DLQHandler
javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: No ClassLoaders found for: org.jboss.jms.client.JBossConnectionFactory (no security manager: RMI class loader disabled)]
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:713)
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
        at javax.naming.InitialContext.lookup(InitialContext.java:347)
        at org.jboss.ejb.plugins.jms.DLQHandler.createService(DLQHandler.java:151)
        at org.jboss.system.ServiceMBeanSupport.jbossInternalCreate(ServiceMBeanSupport.java:245)
        at org.jboss.system.ServiceMBeanSupport.create(ServiceMBeanSupport.java:173)
        ...

means that your Naming service was configured with a CallByValue semantics. There are two solutions
for this situation:

1) Enable JNDI call by reference semantics.

To do that, modify the Naming (JNDI) service configuration and set its "CallByValue" attribute to "false".

The Naming configuration file is $JBOSS_HOME/server/default/deploy/naming-service.xml for an installer-generated JBoss configuration and $JBOSS_HOME/server/conf/jboss-service.xml (the JNDI section, search for "jboss:service=Naming") for a raw installation.

2) In case you don't want to change JNDI CallByValue semantics, deploy the MDB in the same class loading domain as the Messaging server.