Using message-driven beans and JMS

This sample shows how to run message-driven beans (MDBs) and use the Java Message Service (JMS) in EAServer. JMS is a standard API for asynchronous messaging in Java. MDBs are EJB 2.0 components that respond to messages published in the message service. For information on using JMS and creating MDBs, see Chapter 31, “Using the Message Service,” in the EAServer Programmer’s Guide.

The file html/classes/MDBSample.jar contains all the files you need to deploy and run the sample, as well as the source code. Follow the instructions below to deploy the MDB and run the sample client. When you import the JAR file, EAServer Manager creates and configures the MDB component and also extracts the source files to the html/classes/Sample/MDBSample directory in your installation.

StepsImporting the JAR file, installing the MDB, and running the JMS client

  1. If the message service is not running, configure and start it as described in Chapter 8, “Setting up the Message Service,” in the EAServer System Administration Guide.

  2. Using EAServer Manager, import the MDBSample JAR file:

    1. Highlight the Packages folder.

    2. Choose File | Deploy | Jaguar JAR.

    3. In the Specify JAR File dialog box, click Browse and select the /html/classes/MDBSample.jar file.

    4. Click OK.

  3. Install the MDB component:

    1. Highlight the Jaguar | Installed Packages folder.

    2. Choose File | Install Package.

    3. In the Package wizard, click Install an Existing Package.

    4. In the list of packages, highlight MDBSample, then click OK.

  4. Restart the server.

  5. At a command prompt, run the JMS client:On Windows:

    %JAGUAR%\html\classes\Sample\MDBSample\run.bat
    

    On UNIX:

    $JAGUAR/html/classes/Sample/MDBSample/run.sh
    

    The console window displays the program status.

When you run the JMS client, it sends a message to the message queue myQueue; the MDB listens on this queue. When the MDB receives the message, it sends the message to the queue yourQueue, and the client receives the message from yourQueue. The message queues are created automatically when you run the JMS client.