background image

Transactions JMS Client Example

<< The Vendor Message Listener | Compile and Package the Program >>
<< The Vendor Message Listener | Compile and Package the Program >>

Transactions JMS Client Example

The program contains five classes: Retailer, Vendor, GenericSupplier,
VendorMessageListener
, and Order. The program also contains a main method and a method
that runs the threads of the Retailer, Vendor, and two supplier classes.
All the messages use the MapMessage message type. Synchronous receives are used for all
message reception except for the case of the vendor processing the replies of the suppliers.
These replies are processed asynchronously and demonstrate how to use transactions within a
message listener.
At random intervals, the Vendor class throws an exception to simulate a database problem and
cause a rollback.
All classes except Retailer use transacted sessions.
The program uses three queues named jms/AQueue, jms/BQueue, and jms/CQueue, and one
topic named jms/OTopic.
Vendor
Retailer
Supplier
1
Supplier
N
Vendor
OrderQ
Retailer
ConfirmQ
Supplier
Order
Topic
Vendor
ConfirmQ
1.
2a.
2b.
6.
5.
4.
3.
3.
3.
3.
Message Send
Message Receive
Message Listen
FIGURE 31­10
Transactions: JMS Client Example
Creating Robust JMS Applications
Chapter 31 · The Java Message Service API
951