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 />
JMS doesn't attempt to define a set of APIs for all the possible options on a queue. It<br />
should be possible to set these options administratively, using the vendor-specific<br />
administration capabilities. Figure 5.1 shows what a graphical administration tool for<br />
queues would look like. Most vendors supply a command-line administration tool, a<br />
graphical administration tool, or an API for administering queues at runtime. Some<br />
vendors supply all three.<br />
Figure 5.1. Queues are created and administered using vendor-specific administration tools<br />
Using vendor-specific administration APIs to create and configure a queue may be<br />
convenient at times. However, it is not very portable, and may require that the application<br />
have administrator privileges.<br />
JMS provides a QueueSession.createQueue(String queueName) method, but this is not<br />
intended to define a new queue in the messaging system. It is intended to return a Queue<br />
object that represents an existing queue. There is also a JMS-defined method for creating a<br />
temporary queue that can only be consumed by the JMS client that created it:<br />
QueueSession.createTemporaryQueue( ). A temporary queue is similar to a temporary<br />
topic, and could have been used in our example just like the TemporaryTopic was used in<br />
Chapter 4.<br />
5.4 Load Balancing Using Multiple QueueSessions<br />
A queue may have multiple receivers attached to it for the purpose of distributing the<br />
workload of message processing. The JMS specification states that this capability must be<br />
implemented by a JMS provider, although it does not define the rules for how the<br />
messages are distributed among consumers. A sender could use this feature to distribute<br />
messages to multiple instances of an application, each of which would provide its own<br />
receiver.<br />
When multiple receivers are attached to a queue, each message in the queue is delivered to<br />
one receiver. The absolute order of messages cannot be guaranteed, since one receiver may<br />
process messages faster than another. From the receiver's perspective, the messages it<br />
consumes should be in relative order; messages delivered to the queue earlier are<br />
consumed first. However, if a message needs to be redelivered due to an acknowledgment<br />
failure, it is possible that it could be delivered to another receiver. The other receiver may<br />
79