O'Reilly logo

Enterprise JavaBeans, Fourth Edition by Richard Monson-Haefel, Bill Burke, Sacha Labourey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 12.2: The Message-Driven Bean

This exercise is an extension of the preceding one. You’ll add a message-driven bean (MDB), ReservationProcessor, which plays the same role as the TravelAgent EJB but receives its booking orders through a JMS queue instead of synchronous RMI invocations.

To test the MDB, you’ll build a new client application that makes multiple reservations in batch, using a JMS queue that’s bound to the MDB. You’ll also build a second client application that listens on another queue to receive booking confirmations.

Along the way, you’ll learn how to create a new JMS queue in JBoss and configure a message-driven bean (MDB).

Start Up JBoss

If JBoss is already running, there is no reason to restart it.

Initialize the Database

Because the exercise uses the ProcessPayment EJB used in recent exercises, the database must contain the PAYMENT table. The createdb and dropdb Ant targets, Java code, and clients here have been borrowed from exercise 12_1.

If you haven’t already dropped the PAYMENT table after running the examples in Exercise 12.1, do so now by running the dropdb Ant target.

C:\workbook\ex12_2>ant dropdb
Buildfile: build.xml

prepare:

compile:

dropdb:
     [java] Looking up home interfaces..
     [java] Dropping database table...

BUILD SUCCESSFUL

Then re-create the PAYMENT database table by running the createdb Ant target:

C:\workbook\ex12_2>ant createdb Buildfile: build.xml prepare: compile: ejbjar: createdb: [java] Looking up home interfaces.. [java] Creating database table... ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required