JMS defines a generic view of a message service. It is important to understand
this view, and how it maps onto the underlying MQe system. The generic JMS
model is based around the following interfaces that are defined in Sun's javax.jms
package:
- Connection
- This provides a connection to the underlying messaging service and is
used to create Sessions.
- Session
- This provides a context for producing and consuming messages, including
the methods used to create MessageProducers and MessageConsumers.
- MessageProducer
- This is used to send messages.
- MessageConsumer
- This is used to receive messages.
- Destination
- This represents a message destination.
Note: A connection is thread safe, but sessions, message producers, and message
consumers are not. While the JMS specification allows a Session to be used
by more than one thread, it is up to the user to ensure that Session resources
are not concurrently used by multiple threads. The recommended strategy is
to use one Session per application thread.
Therefore, in MQe terms:
- Connection
- This provides a connection to an MQe queue manager. All the Connections
in a JVM must connect to the same queue manager, because MQe supports a single
queue manager per JVM. The first connection created by an application will
try and connect to an already running queue manager, and if that fails will
attempt to start a queue manager itself. Subsequent connections will connect
to the same queue manager as the first connection.
- Session
- This does not have an equivalent in MQe
- Message producer and message consumer
- These do not have direct equivalents in MQe. The MessageProducer invokes
the putMessage() method on the queue manager. The MessageConsumer
invokes the getMessage() method on the queue manager.
- Destination
- This represents an MQe queue.
MQe JMS can put messages to a local queue or an asynchronous remote queue
and it can receive messages from a local queue. It cannot put messages to
or receive messages from a synchronous remote queue.
The generic JMS interfaces are subclassed into more specific versions for
Point-to-point and Publish or Subscribe behavior. MQe implements the Point-to-point
subclasses of JMS. The Point-to-point subclasses are:
- QueueConnection
- Extends Connection
- QueueSession
- Extends Session
- QueueSender
- Extends MessageProducer
- QueueReceiver
- Extends MessageConsumer
- Queue
- Extends destination
It is recommended that you write application programs that
use only references to the interfaces in javax.jms. All vendor-specific information
is encapsulated in implementations of:
- QueueConnectionFactory
- Queue
These are known as "administered objects", that is, objects that can
be administered and stored in a JNDI namespace. A JMS application can retrieve
these objects from the namespace and use them without needing to know which
vendor provided the implementation. However, on small devices looking up objects
in a JNDI namespace may be impractical or represent an unnecessary overhead.
We, therefore, provide two versions of the
QueueConnectionFactory and
Queue classes.
The parent classes, MQeQueueConnectionFactory.class, MQeJMSQueue.class,
provide the base JMS functionality but cannot be stored in JNDI, while subclasses,
MQeJNDIQueueConnectionFactory.class, and the MQeJMSJNDIQueue.class, add the
necessary functionality for them to be stored and retrieved from JNDI.