Chapter 7. Message-Driven Beans

Two message-driven beans examples are provided with JOnAS. The first and simplest is located in $JONAS_ROOT/examples/src/mdb/samplemdb; it contains a Message Driven bean listening to a topic and an MdbClient, which is a pure JMS Client that sends 10 messages on the corresponding topic. This is a very good example of how to write and use message driven beans.

$JONAS_ROOT/examples/src/mdb/sampleappli has the second, more complex, example. The example contains two Message Driven beans—one listening to a topic (StockHandlerBean) and the other listening to a queue (OrderBean), an Entity bean with container managed persistence (StockBean), and a Stateless Session bean for creating the table used in the database.

SampleAppliClient sends several messages on the topic. At receipt of the message, the StockHandlerBean updates the database via the StockBean and sends a message to the Queue inside a global transaction. All the EJBs are involved in transactions that may commit or rollback.

7.1. Building the Examples

The simplest way to compile this and all examples is to start in the $JONAS_ROOT/examples/src directory and enter the following command as user jonas:

ant -find build.xml install

This compiles all examples in the $JONAS_ROOT/examples/src directory.