10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Writing Simple JMS Client Applications<br />

See “A Simple Example of Browsing Messages in a Queue” on page 920 for an example of the use<br />

of a QueueBrowser object.<br />

<strong>The</strong> createBrowser method allows you to specify a message selector as a second argument<br />

when you create a QueueBrowser. For information on message selectors, see “JMS Message<br />

Selectors” on page 903.<br />

<strong>The</strong> JMS API provides no mechanism for browsing a topic. Messages usually disappear from a<br />

topic as soon as they appear: if there are no message consumers to consume them, the JMS<br />

provider removes them. Although durable subscriptions allow messages to remain on a topic<br />

while the message consumer is not active, no facility exists for examining them.<br />

JMS Exception Handling<br />

<strong>The</strong> root class for exceptions thrown by JMS API methods is JMSException. Catching<br />

JMSException provides a generic way of handling all exceptions related to the JMS API.<br />

<strong>The</strong> JMSException class includes the following subclasses, which are described in the API<br />

documentation:<br />

■ IllegalStateException<br />

■ InvalidClientIDException<br />

■ InvalidDestinationException<br />

■ InvalidSelectorException<br />

■ JMSSecurityException<br />

■ MessageEOFException<br />

■ MessageFormatException<br />

■ MessageNotReadableException<br />

■ MessageNotWriteableException<br />

■ ResourceAllocationException<br />

■ TransactionInProgressException<br />

■ TransactionRolledBackException<br />

All the examples in the tutorial catch and handle JMSException when it is appropriate to do so.<br />

Writing Simple JMS Client Applications<br />

906<br />

This section shows how to create, package, and run simple JMS client programs packaged as<br />

stand-alone application clients. <strong>The</strong>se clients access a <strong>Java</strong> <strong>EE</strong> server. <strong>The</strong> clients demonstrate<br />

the basic tasks that a JMS application must perform:<br />

■ Creating a connection and a session<br />

■ Creating message producers and consumers<br />

■ Sending and receiving messages<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!