# Message Driven Bean Behavior on Failure Example

$Revision: 82920 $

## Overview

This example deploys a simple Message Driven Bean that processes messages sent to a test queue. The Message Driven Bean is coded in such a way that upon the first arrival of a message, it throws a RuntimeException, simulating a runtime processing failure.
The expected behavior of the MDB Container is to try to redeliver the message, which is what it hopefully does. Since the example framework took the precaution to insure that there is only one single type of MDB container listening on the example queue, the messages will be redelivered to an MDB of the same type. Upon the second arrival, the MDB instance will "let the message pass", will correctly "process" it and forward the result to temporary queue created by the sender for exactly this purpose. The example is considered successful if the sender receives the acknowledgment message. The successful example proves that message redelivery on failure works.
This example relies on having access to a running JBoss default instance. However, the example will automatically deploy its own queue, unless a queue with the same name is already deployed.

## 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-5.0.0.GA\server\default\deploy, then your JBOSS_HOME value should be C:\jboss-5.0.0.GA
2. Go to the example's home directory
cd ...\examples\mdb-failure
3. Run the example:
ant
The output of a successful run should be similar to:

    $ ant
    Buildfile: build.xml

    identify:
         [echo] ###########################################################################
         [echo] #                    Running the MDB Failure example                      #
         [echo] ###########################################################################
         [echo] The queue:      testQueue
         [echo] The client jar: ../../../output/lib/jboss-messaging-client.jar

    sanity-check:

    init:
        [mkdir] Created dir: C:\java\messaging\docs\examples\mdb-failure\output\classes\META-INF
        [mkdir] Created dir: C:\java\messaging\docs\examples\mdb-failure\output\lib\META-INF
        [mkdir] Created dir: C:\java\messaging\docs\examples\common\output\classes

    compile:
        [javac] Compiling 5 source files to C:\java\messaging\docs\examples\common\output\classes
        [javac] Compiling 2 source files to C:\java\messaging\docs\examples\mdb-failure\output\classes
        [javac] Note: C:\java\messaging\docs\examples\mdb-failure\src\org\jboss\example\jms\mdbfailure\MDBFailureExample.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\mdb-failure\output\classes\META-INF
          [jar] Building jar: C:\java\messaging\docs\examples\mdb-failure\output\lib\mdb-failure-example.jar

    deploy:
         [copy] Copying 1 file to C:\jboss-4.2.0.GA\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.4.1.GA (1.4)
         [java]
         [java] #####################
         [java] ###    SUCCESS!   ###
         [java] #####################

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

    undeploy:
       [delete] Deleting: C:\jboss-4.2.0.GA\server\messaging\deploy\mdb-failure-example.jar

    BUILD SUCCESSFUL
    Total time: 19 seconds