O'Reilly logo

Java Message Service by Richard Monson-Haefel, David A Chappell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The QWholesaler and QRetailer

Let's rethink our wholesaler/retailer scenario in terms of the distinction between the two message models. The pub/sub model is well suited for sending price quotes, since that is naturally a one-to-many broadcast. However, when the retailer responds with a "buy" order, it is more appropriate to use a point-to-point queue. In the real world, retailers naturally deal with many wholesalers, and you would only send a purchase order to the wholesaler that offered the quote.

From the user's perspective, the QWholesaler and QRetailer examples that we'll develop now are functionally equivalent to the Wholesaler and Retailer examples introduced in Chapter 4. The difference lies in the use of the point-to-point queue for responses to price quotes. If you wish to see these classes in action, start your JMS provider and execute the following commands, each in a separate command window:

java chap5.B2B.QWholesaler localhost username password
java chap5.B2B.QRetailer localhost username password

The QRetailer Class

Here is the listing for the QRetailer class in its entirety. Later, we will examine this class in detail:

import java.util.StringTokenizer; import java.util.Properties; import javax.naming.InitialContext; import javax.jms.TopicConnectionFactory; import javax.jms.QueueConnectionFactory; import javax.jms.Topic; import javax.jms.Queue; import javax.jms.Session; import javax.jms.StreamMessage; import javax.jms.TextMessage; public class QRetailer implements ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required