Chapter 9. Scenario: JMS messaging

Table of Contents

9.1. Description
9.2. Configuring the server
9.3. Running the habitat

This example provides information on the following topics:

9.1. Description

This example demonstrates how to use the JMS tasks by making an agent communicate with two Enterprise Java Beans.

Figure 9.1. Global overview

Global overview

When the agent is started, the agent adds a ReactiveJMSTask to listen to messages in the jms/AgentQueue queue. Then, it sends a TextMessage to the jms/InQueue (1). The TextMessage is received by the MessageDrivenBean MessageReceiverEJB (2). The MessageReceiver executes a lookup to locate the SessionBean DateEJB (3). The DateEJB is located and asked to send the current date to the jms/AgentQueue (4). The message is then received by the agent in the handleJMSMessage(Message message) as an ObjectMessage (5) that is printed out to the screen.

9.2. Configuring the server

The JMS example requires installation of a J2EE server. The J2EE server should also have the required queues and EJBs used by the example. This example is configured to work with Sun's J2EE reference implementation.

  • Download and install the Sun's J2EE reference implementation.

  • Set the environment variable, J2EE_HOME, to the directory where J2EE is installed. For example,

      set J2EE_HOME=c:\java\j2eesdk

  • Start the J2EE server in verbose mode:

      %J2EE_HOME%\bin\j2ee -verbose

  • When you start the server for the first time, execute the following commands. Be sure to add the queues used by the example:

      %J2EE_HOME%\bin\j2eeadmin -addJmsDestination jms/AgentQueue queue
      %J2EE_HOME%\bin\j2eeadmin -addJmsDestination jms/InQueue queue

  • Add the Enterprise Java Beans to the server:

      %J2EE_HOME%\bin\deploytool

    Open the date.ear included in the scenarios/jars directory. Deploy the Java Beans by choosing the menu Tools -> Deploy...

If you use Windows 98, you may have to change the bat file included in the J2EE reference implementation and replace the %* at the end of the bat file with a %1 %2 %3 %4. You may also need to execute the file setenv.bat before starting the deploytool.

9.3. Running the habitat

The J2EE_HOME environment variable should be set as described in the previous section.

To contact the Enterprise Java Beans, start the habitat with the agent:

  habitat.bat jms.xml

The agent will contact the EJBs and print the date it received from the J2EE server to the screen.

The JMS example consists of an agent and two EJBs already compiled in the release. If you want to recompile the project, use the following commands:

  build -Dj2ee.home=%J2EE_HOME% jms