JMS 1.1 introduced new elements to the API that allow messaging clients to use the same interfaces and methods to do either point-to-point messaging or publish-subscribe messaging. In JMS 1.0 (used in J2EE 1.3 and earlier environments), a client needed to use the specific subclasses discussed in the previous sections.
As an example, our previous clients had to explicitly cast the
ConnectionFactory objects retrieved from the
JNDI context in order to create a
PTPMessagingClient, for example, had to
perform the following sequence of steps in order to create a
QueueSession, to be more precise):
Context ctx = new InitialContext(); QueueConnectionFactory connFactory = (QueueConnectionFactory)ctx.lookup(cFactoryJNDIName); QueueConnection mQueueConn = connFactory.createQueueConnection(); Queue mQueue = (Queue)ctx.lookup(queueJNDIName); QueueSession mSession = mQueueConn.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
Note that we’ve simplified this code from the original code in Example 11-2 by eliminating a lot of exception handling.
With the new unified API elements added in JMS 1.1, a client can
use the common base classes (
Destination instead of
Connection instead of
TopicConnection, etc.). With JMS 1.1, we can
shorten that code example considerably:
Context ctx = new InitialContext(); Connection Factory connFactory = ConnectionFactory)ctx.lookup(cFactoryJNDIName); Connection mConn ...