Chapter 7. Application and system design guidelines 209
of either MessageConsumer and MessageProducer can only be used by a single
client. JMS Sessions are opened for the duration of message sending or
receiving; after this the session can be closed.
When a session is opened, the correct session acknowledgment must be
selected from a performance perspective. In our sample scenario, we selected
AUTO_ACKNOWLEDGE. This policy specifies that the message be delivered
once and only once. The server must send an acknowledgment back, so the
server incurs an overhead to implement this policy. The
DUPS_OK_ACKNOWLEDGE setting resends the message until an
acknowledgment is sent from the server. The server will operate in a lazy
acknowledge mode, thereby reducing the overhead on the server but resulting in
an increase in network traffic. With the most overhead of the three settings,
CLIENT_ACKNOWLEDGE will cause the server to wait until a request for
acknowledgment is sent from the client. Usually the client calls the sent
message’s acknowledge method.
On completion of interaction with the message producer or consumer (sender or
receiver), the session needs to be closed. If the connection is closed, the session
belonging to this connection is automatically closed.
The message producers and consumers must also be closed when you finish
sending and receiving messages. Again if the connection is closed, the
producers and consumers are automatically closed.
Garbage collection of Java cannot be relied upon to clean out objects in a timely
manner. It is always a good practice to call the close of any resource-bound
object.
For further information, read the JMS specification at:
http://java.sun.com/products/jms/docs.html
7.5.5 JMS and JNDI
The Java Naming and Directory Interface (JNDI) API implementation provides
directory and naming functionality to programs developed in Java. This allows
Java programs to discover and retrieve objects of any type from the JNDI name
space.
JMS has two types of administered objects:
򐂰 ConnectionFactory
򐂰 Destination
An administrator can place objects of these types in the JNDI name space to be
accessed by messaging applications.

Get Patterns: Implementing Self-Service in an SOA Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.