Java Reference
In-Depth Information
•
MessageNotWriteableException
•
ResourceAllocationException
•
TransactionInProgressException
•
TransactionRolledBackException
All the examples in the tutorial catch and handle
JMSException
when it is appropriate
to do so.
Creating Robust JMS Applications
This section explains how to use features of the JMS API to achieve the level of reliability
and performance your application requires. Many people choose to implement JMS ap-
plications because they cannot tolerate dropped or duplicate messages and because they
require that every message be received once and only once. The JMS API provides this
functionality.
The most reliable way to produce a message is to send a
PERSISTENT
message within a
transaction. JMS messages are
PERSISTENT
by default. A
transaction
is a unit of work
into which you can group a series of operations, such as message sends and receives, so
that the operations either all succeed or all fail. For details, see “
Specifying Message Per-
sistence
”
on page
361
and “
Using JMS API Local Transactions
” on page
366
.
The most reliable way to consume a message is to do so within a transaction, either from
a queue or from a durable subscription to a topic. For details, see “
Creating Temporary
Destinations
”
on page
363
, “
Creating Durable Subscriptions
”
on page
364
,
and “
Using
JMS API Local Transactions
”
on page
366
.
For other applications, a lower level of reliability can reduce overhead and improve per-
formance. You can send messages with varying priority levels (see
“
Setting Message Pri-
ority Levels
” on page
362
) and you can set them to expire after a certain length of time
(see “
Allowing Messages to Expire
” on page
362
)
.
The JMS API provides several ways to achieve various kinds and degrees of reliability.
This section divides them into two categories, basic and advanced.
The following sections describe these features as they apply to JMS clients. Some of the
features work differently in Java EE applications; in these cases, the differences are noted
here and are explained in detail in “
Using the JMS API in Java EE Applications
”
on page
Using Basic Reliability Mechanisms
The basic mechanisms for achieving or affecting reliable message delivery are as follows: