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.
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
have already processed more recently delivered messages, which would place the<br />
redelivered message out of the original order.<br />
If you would like to see multiple recipients in action, try starting two instances of<br />
QWholesaler and three or more instances of QRetailer, each in a separate command<br />
window:<br />
java chap5.B2B.QWholesaler localhost WHOLESALER1 password<br />
java chap5.B2B.QWholesaler localhost WHOLESALER2 password<br />
java chap5.B2B.QRetailer localhost RETAILER1 password<br />
java chap5.B2B.QRetailer localhost RETAILER2 password<br />
java chap5.B2B.QRetailer localhost RETAILER3 password<br />
In the command window for one of the QWholesaler applications, type the following<br />
command:<br />
Surfboards, 999.99, 499.99<br />
Upon hitting the enter key, each instance of QRetailer will get the price quote, and<br />
respond with a "Buy" order. If you have three QRetailers up and running, you should see<br />
two of the messages going to one of the QWholesalers, and one going to the other.<br />
5.5 Examining a Queue<br />
If you don't see this behavior, load balancing may not be broken. It<br />
may mean that vendor-specific queue settings are preventing load<br />
balancing; you may need to send more than three messages<br />
simultaneously to populate the queue enough to cause the messages<br />
to be delivered to more than one consumer. For example, in SonicMQ<br />
there is a configurable pre-fetch count that determines how many<br />
messages may be batched together as they are delivered to a<br />
consumer. The default is three messages, so the messages get<br />
delivered to each consumer three at a time. The SonicMQ version of<br />
these samples has some code that sets the value to one, which makes<br />
load balancing work properly with only three clients:<br />
...<br />
qReceiver.setPrefetchThreshold(0);<br />
qReceiver.setPrefetchCount(1);<br />
...<br />
It is likely that other vendors have the same kind of optimization, so<br />
you should check that possibility if you are using a vendor other than<br />
SonicMQ and don't see the proper behavior.<br />
A QueueBrowser is a specialized object that allows you to peek ahead at pending messages<br />
on a Queue without actually consuming them. This feature is unique to point-to-point<br />
messaging. Queue browsing can be useful for monitoring the contents of a queue from an<br />
administration tool, or for browsing through multiple messages to locate a message that is<br />
80