|
| 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 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
- Configure the Server
- Run 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:
- build.cmd for Windows NT/2000
- build.sh for UNIX
These scripts build the example and place the files in the
correct locations:
- Client files: in /weblogic600/config/examples/clientclasses/
- EJB: in /weblogic600/config/examples/applications/jta_ejb_jmsjdbc.jar
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
- Start the server with the examples
configuration in a new command shell.
- Bring up the Administration Console in your browser.
-
Click to expand the JMS node in the left pane.
-
Click to expand the JMS Connection Factories node in the left pane.
-
Choose the server target for the exampleQueue connection factory as follows:
-
Select the exampleQueue node.
The exampleQueue connection factory configuration information displays in the
right pane.
-
Select the Targets tab in the right pane to display the Available and Chosen
targets.
-
Move the examplesServer target to the Chosen column and click the Apply button to
save the assignment.
- Click to expand the JDBC node in the left pane.
- Click to expand the Connection Pools node in the left pane.
-
Verify that the demoXAPool is deployed on the examplesServer as follows:
- Select the demoXAPool node in the left pane.
- Select the Targets tag in the right pane and verify that the examplesServer appears in the Chosen column.
-
Verify that the demoPool is deployed on the examplesServer as follows:
- Select the demoPool node in the left pane.
- Select the Targets tag in the right pane and verify that the examplesServer appears in the Chosen column.
- Click to expand the Tx 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 Targets tag in the right pane and verify that the examplesServer appears in the Chosen column.
- Click to expand the Data Sources node in the left pane.
-
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 Targets tag in the right pane and verify that the examplesServer appears in the Chosen column.
Run the Example
- If necessary,
restart the WebLogic Server in a new command shell.
-
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).
- 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 COMMITTED
There's More...
Read more about WebLogic JTA in
Programming
WebLogic JTA.
Copyright © 2000 BEA Systems, Inc. All Rights Reserved.