WebLogic Server 6.0 Code Examples, BEA Systems, Inc.

Package examples.jta.jmsjdbc

This example shows how to use JTA to perform distributed transactions using the two phase commit protocol across two XA resources: a JMS queue and a Cloudscape database.

See:
          Description

Interface Summary
ReceiveInTx Interface for an EJB that receives messages from a JMS queue.
ReceiveInTxHome Home interface for a ReceiveInTx EJB.
 

Class Summary
Client This example shows how to use JTA to perform distributed transactions and two phase commit across two XA resources: JMS queue, and Cloudscape database.
QueueSend Utility class uses to create JMS objects and send a message to a queue.
ReceiveInTxBean ReceiveInTxBean is a stateless session bean using bean-managed transaction.
 

Package examples.jta.jmsjdbc Description

This example shows how to use JTA to perform distributed transactions using the two phase commit protocol across two XA resources: a JMS queue and a Cloudscape database.

This example does the following:

The following section describes how to build and run the example:

  1. Build the Example
  2. Configure the Server
  3. Run the Example

Build the Example

Set up your development shell as described in Setting up your environment.

We provide separate build scripts for Windows NT/2000 and UNIX:

These scripts build the example and place the files in the correct locations:

Running the build script places the EJB in weblogic600/config/examples/applications, where it automatically deploys once the server is started. If you are already running the server and build the EJB, it is automatically placed in this directory and instantly deployed.

Additional information on using the build scripts is found in Building Enterprise JavaBean examples

Configure the Server

  1. Start the server with the examples configuration in a new command shell.
  2. Bring up the Administration Console in your browser.
  3. Click to expand the JMS node in the left pane.
  4. Click to expand the JMS Connection Factories node in the left pane.
  5. Choose the server target for the exampleQueue connection factory as follows:
    1. Select the exampleQueue node. The exampleQueue connection factory configuration information displays in the right pane.
    2. Select the Targets tab in the right pane to display the Available and Chosen targets.
    3. Move the examplesServer target to the Chosen column and click the Apply button to save the assignment.
  6. Click to expand the JDBC node in the left pane.
  7. Click to expand the Connection Pools node in the left pane.
  8. Verify that the demoXAPool is deployed on the examplesServer as follows:
    1. Select the demoXAPool node in the left pane.
    2. Select the Targets tag in the right pane and verify that the examplesServer appears in the Chosen column.
  9. Verify that the demoPool is deployed on the examplesServer as follows:
    1. Select the demoPool node in the left pane.
    2. Select the Targets tag in the right pane and verify that the examplesServer appears in the Chosen column.
  10. Click to expand the Tx Data Sources node in the left pane.
  11. Verify that the examples-dataSource-demoXAPool is deployed on the examplesServer as follows:
    1. Select the examples-dataSource-demoXAPool node in the left pane.
    2. Select the Targets tag in the right pane and verify that the examplesServer appears in the Chosen column.
  12. Click to expand the Data Sources node in the left pane.
  13. Verify that the examples-dataSource-demoPool is deployed on the examplesServer as follows:
    1. Select the examples-dataSource-demoPool node in the left pane.
    2. Select the Targets tag in the right pane and verify that the examplesServer appears in the Chosen column.

Run the Example

  1. If necessary, restart the WebLogic Server in a new command shell.

  2. In your development shell, run the StockClient client with the following command:
      $ java examples.jta.jmsjdbc.Client t3://hostname:port
    where:
    hostname
    Host name of the WebLogic Server.
    port
    Port where the WebLogic Server is listening for connections (weblogic.system.ListenPort).
  3. When prompted, enter messages into the client shell. After the last message, enter "quit".
  4. In the client shell, you should see something like the following:
    Enter message ("quit" to quit): hello
    JMS Message Sent: hello
    
    Enter message ("quit" to quit): bea
    JMS Message Sent: bea
    
    Enter message ("quit" to quit): quit
    JMS Message Sent: quit
    
    Data found in database:
    hello
    bea
    
  5. In the server shell, you should see something like the following:
    setSessionContext called
    ejbCreate called
    TRANSACTION BEGUN
    Message Received: hello
    Message Received: bea
    Message Received: quit
    TRANSACTION COMMITTED
    

There's More...

Read more about WebLogic JTA in Programming WebLogic JTA.


Documentation is available at
http://e-docs.bea.com/wls/docs60

Copyright © 2000 BEA Systems, Inc. All Rights Reserved.