O'Reilly - Java Message Service
O'Reilly - Java Message Service
O'Reilly - Java Message Service
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
4.1.1 Running the B2B Application<br />
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
Before looking at the code, let's look at how the application works. As with the Chat<br />
application, the Wholesaler class includes a main( ) method so it can be run as a<br />
standalone <strong>Java</strong> application. It's executed from the command line as follows:<br />
java chap4.B2B.Wholesaler localhost username password<br />
username and password are the authentication information for the client. The Retailer<br />
class can be executed in the same manner:<br />
java chap4.B2B.Retailer localhost username password<br />
Start your JMS server, then run one instance of a Wholesaler client and a Retailer client in<br />
separate command windows. In the Wholesaler client you are prompted to enter an item<br />
description, an old price, and a new price. Enter the following as shown:<br />
Bowling Shoes, 100.00, 55.00<br />
Upon hitting the Enter key, you should see the Retailer application display information on<br />
the screen indicating that it has received a price change notice. You should then see the<br />
Wholesaler indicating that it has received a "buy" order from the Retailer. Here's the<br />
complete interaction with the Wholesaler and the Retailer: [1]<br />
[1] WHOLESALER and RETAILER are usernames you have set up when configuring your JMS<br />
server. passwd1 and passwd2 are the passwords you've assigned to those usernames. If you are<br />
using an evaluation version of a JMS provider, it may not be necessary to set up usernames and<br />
passwords; check your vendor's documentation for more information.<br />
java chap4.B2B.Wholesaler localhost WHOLESALER passwd1<br />
Enter: Item, Old Price, New Price<br />
e.g., Bowling Shoes, 100.00, 55.00<br />
Bowling Shoes, 100.00, 55.00<br />
Order received - 1000 Bowling Shoes from DurableRetailer<br />
-----------------------<br />
java chap4.B2B.Retailer localhost RETAILER passwd2<br />
Retailer application started.<br />
Received Hot Buy: Bowling Shoes, 100.00, 55.00<br />
Buying 1000 Bowling Shoes<br />
Here's what happened. The Wholesaler publishes a price quotation on a topic, "Hot Deals,"<br />
which is intended for one or more Retailers. The Retailers subscribe to the "Hot Deals"<br />
topic in order to receive price quotes. The Retailer application has no interaction with a<br />
live user. Instead, it has an autoBuy( ) method that examines the old price and the new<br />
price. If the new price represents a reduction of greater than ten percent, the Retailer<br />
sends a message back to the Wholesaler on the "Buy Order" topic, telling it to purchase<br />
1,000 items. In JMS terms, the Wholesaler is a producer of the "Hot Deals" topic and a<br />
consumer of the "Buy Order" topic. Conversely, the Retailer is a consumer of the "Hot<br />
Deals" topic and a producer of the "Buy Order" topic, as illustrated in Figure 4.1.<br />
54