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... ...
Get Enterprise JavaBeans, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.