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
QRetailer examples that we'll develop
now are functionally equivalent to the
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:
localhost username passwordjava chap5.B2B.
localhost username password
Here is the listing for the
class in its entirety. Later, we will examine this
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 ...