Sun Java System Application Server 

Samples Index

The Message Driven Bean (MDB) Simple Sample Application

The Message Driven Bean (MDB) simple application provides an example of an MDB, which is an enterprise bean that allows Java Enterprise Edition (J2EE) applications to process messages asynchronously. An MDB acts as a JMS message listener, which is similar to an event listener except that it receives messages instead of events. The messages may be sent by any J2EE component (an application client, another enterprise bean, or a web component), or by a JMS application or system that does not use J2EE technology.

Building, Deploying, and Running the Application

The general instructions for building, deploying, and running sample applications are provided in Building, Deploying, and Running Sample Applications. In reading this document, use the following application-specific variables for this application:

Follow this general procedure:

  1. Build the Application. The build file, build.xml, is in the app_dir directory, specifically, install_dir/samples/ejb/mdb/apps/simple.
  2. Configure JMS Resources
  3. Deploy the Application. The EAR file is install_dir/samples/ejb/mdb/apps/simple/mdb-simple.ear.
  4. Run the client, as described below.

Configuring JMS Resources

There are three ways to configure resources for this sample application:

Running the Client

To run the application:

  1. Change your working directory to be the application base directory:
    cd app_dir
  2. If you are using the predeployed samples domain (Platform Edition only), enter this command to retrieve client stubs:
    asadmin get-client-stubs --port 4858 --appname mdb-simple
    This step is not required if you deployed the application yourself.
  3. Run the application in the application client container:
    install_dir/bin/appclient
     -client mdb-simpleClient.jar -name SimpleMessageClient
     -textauth -xml domain_root_dir/domain_name/config/sun-acc.xml

The results will be something like this:

Sending message: This is message 1
Sending message: This is message 2
Sending message: This is message 3

The MDB receives the messages, which are then printed in the log file server.log:

MESSAGE BEAN: Message received: This is message 1
MESSAGE BEAN: Message received: This is message 2
MESSAGE BEAN: Message received: This is message 3

For example, to run client in the samples domain, enter this command:

appclient -client mdb-simpleClient.jar
-name SimpleMessageClient -textauth
-xml install_dir/domains/samples/config/sun-acc.xml

Troubleshooting

If you encounter problems, in addition to viewing the Application Server log files, look at the MQ broker log files, for example:


Copyright © 2006 Sun Microsystems, Inc. All rights reserved.