10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

FIGURE 31–10 Transactions: JMS Client Example<br />

Retailer<br />

1. 2a. 2b.<br />

Vendor<br />

OrderQ<br />

Vendor<br />

6. 5. 4.<br />

Retailer<br />

ConfirmQ<br />

Message Send<br />

Message Receive<br />

Message Listen<br />

<strong>The</strong> program contains five classes: Retailer, Vendor, GenericSupplier,<br />

VendorMessageListener, and Order. <strong>The</strong> program also contains a main method and a method<br />

that runs the threads of the Retailer, Vendor, and two supplier classes.<br />

All the messages use the MapMessage message type. Synchronous receives are used for all<br />

message reception except for the case of the vendor processing the replies of the suppliers.<br />

<strong>The</strong>se replies are processed asynchronously and demonstrate how to use transactions within a<br />

message listener.<br />

At random intervals, the Vendor class throws an exception to simulate a database problem and<br />

cause a rollback.<br />

All classes except Retailer use transacted sessions.<br />

<strong>The</strong> program uses three queues named jms/AQueue, jms/BQueue, and jms/CQueue, and one<br />

topic named jms/OTopic.<br />

Before you run the program, do the following:<br />

1. In a terminal window, go to the following directory:<br />

Supplier<br />

Order<br />

Topic<br />

Vendor<br />

ConfirmQ<br />

tut-install/javaeetutorial5/examples/jms/advanced/transactedexample/<br />

2. Create the necessary resources using the following command:<br />

Creating Robust JMS Applications<br />

3.<br />

3.<br />

3.<br />

3.<br />

Supplier<br />

1<br />

Supplier<br />

N<br />

Chapter 31 • <strong>The</strong> <strong>Java</strong> Message Service API 945

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!