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:
Build the Example
- Set up your development shell as described in Setting up your environment.
- Change to the following directory: $WL_HOME/samples/server/examples/src/examples/jta\jmsjdbc, which contains an ant build script to build the example.
- Enter the following command to execute the build script:
antThis 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.
- 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
- Start the server with the examples configuration in a new command shell.
- Bring up the Administration Console in your browser.
- Click to expand the Services -> JMS -> JMS Connection Factories nodes in the left pane.
- Verify that the exampleQueue connection factory is deployed on the examplesServer as follows:
- Select the exampleQueue node. The exampleQueue connection factory configuration information displays in the right pane.
- Select the Target and Deploy tab in the right pane and make sure that examplesServer is selected.
- Click to expand the Services ->JDBC -> Connection Pools nodes in the left pane.
- Verify that the demoXAPool connection pool is deployed on the examplesServer as follows:
- Select the demoXAPool node in the left pane.
- Select the Target and Deploy tab in the right pane and make sure that examplesServer is selected.
- Select the Monitoring tab and make sure that the demoXAPool is running on the examplesServer.
- Verify that the demoPool connection pool is deployed on the examplesServer as follows:
- Select the demoPool node in the left pane.
- Select the Target and Deploy tab in the right pane and make sure that examplesServer is selected.
- Select the Monitoring tab and make sure that the demoPool is running on the examplesServer.
- Click to expand the Data Sources node in the left pane.
- Verify that the examples-dataSource-demoXAPool is deployed on the examplesServer as follows:
- Select the examples-dataSource-demoXAPool node in the left pane.
- Select the Target and Deploy tab in the right pane and make sure that examplesServer is selected.
- Verify that the examples-dataSource-demoPool is deployed on the examplesServer as follows:
- Select the examples-dataSource-demoPool node in the left pane.
- Select the Target and Deploy tab in the right pane and verify that examplesServer is selected.
Run the Example
- In your development shell, run the Client client with the following command:
prompt> java examples.jta.jmsjdbc.Client t3://hostname:portwhere:
- hostname
- Host name of the WebLogic Server.
- port
- Port where the WebLogic Server is listening for connections.
- When prompted, enter messages into the client shell. After the last message, enter "quit".
- 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- 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 COMMITTEDRead more about WebLogic JTA in Programming WebLogic JTA.