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 Pointbase database.

See:

 

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 Pointbase 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 Pointbase database.

This example does the following:

  • The Client prompts the user for test messages. The Client then sends the messages to the JMS queue, initializes the database table, and calls ReceiveInTxBean EJB.
  • ReceiveInTxBean EJB in turn begins a distributed transaction, receives messages from the JMS queue, updates the database, and then commits the distributed transaction.
  • The Client then verifies that the data is updated in the database, and cleans up the database table.

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

  1. Set up your development shell as described in Setting up your environment.
  2. Change to the following directory: $WL_HOME/samples/server/examples/src/examples/jta\jmsjdbc, which contains an ant build script to build the example.
  3. Enter the following command to execute the build script:

    ant

    This script builds the example and places the files in the correct locations:

    • Client files: in %SAMPLES_HOME%\server\examples\build\clientclasses
    • EJB: in %SAMPLES_HOME%\domains\examples\applications\jta_ejb_jmsjdbc.jar

    Running the build script places the EJB in %SAMPLES_HOME%\domains\examples\applications, where it automatically deploys once the server is started. If the server is already running when you build the EJB, the EJB is automatically placed in this directory and instantly deployed.

  4. Add the new directory where source files are compiled to your classpath:

    set CLASSPATH=$WL_HOME/samples/server/examples/src/examples/jta\jmsjdbc\build;%CLASSPATH%

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 Services -> JMS -> JMS Connection Factories nodes in the left pane.
  4. Verify that the exampleQueue connection factory is deployed on the examplesServer as follows:
    1. Select the exampleQueue node. The exampleQueue connection factory configuration information displays in the right pane.
    2. Select the Target and Deploy tab in the right pane and make sure that examplesServer is selected.
  5. Click to expand the Services ->JDBC -> Connection Pools nodes in the left pane.
  6. Verify that the demoXAPool connection pool is deployed on the examplesServer as follows:
    1. Select the demoXAPool node in the left pane.
    2. Select the Target and Deploy tab in the right pane and make sure that examplesServer is selected.
    3. Select the Monitoring tab and make sure that the demoXAPool is running on the examplesServer.
  7. Verify that the demoPool connection pool is deployed on the examplesServer as follows:
    1. Select the demoPool node in the left pane.
    2. Select the Target and Deploy tab in the right pane and make sure that examplesServer is selected.
    3. Select the Monitoring tab and make sure that the demoPool is running on the examplesServer.
  8. Click to expand the Data Sources node in the left pane.
  9. 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 Target and Deploy tab in the right pane and make sure that examplesServer is selected.
  10. 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 Target and Deploy tab in the right pane and verify that examplesServer is selected.

Run the Example

  1. In your development shell, run the Client client with the following command:
      prompt> 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.
  2. When prompted, enter messages into the client shell. After the last message, enter "quit".
  3. 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
    
  4. 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
    

  Read more about WebLogic JTA in Programming WebLogic JTA.