Support for JMS 2.0 features in WAS version 9.0
JMS 2.0 introduces many new functions that enhance ease of use, simplicity, and asynchronous support of JMS applications. JMS 2.0 is part of the Java EE 7 platform and can be used in Java EE web or EJB applications (along with J2SE environment).
Some of the significant enhancements of JMS 2.0 are as follows:
- Simplified API
- APIs in JMS 2.0 are made simpler and easier to use compared to JMS 1.0. Existing JMS 1.1 APIs are now referred to as classic APIs. Simplified API introduces three new interfaces such as JMSContext, JMSProducer, and JMSConsumer objects. Refer to the JMS 2.0 specifications documentation.
- Support for Autocloseable
- In JMS 2.0, the Connection, Session, MessageProducer, MessageConsumer and QueueBrowser interfaces have been modified to extend the java.lang.Autocloseable interface. Applications can create these objects using a Java SE 7 try-with-resources statement, which eliminates the need for applications to explicitly call close() when the objects are no longer required. Refer to the JMS 2.0 specifications documentation.
- Context dependency injection (injecting JMSContext into Java EE application)
- JMS 2.0 allows JMSContext to be injected into Java EE Web or EJB application. For example: @Inject @JMSConnectionFactory( "jms/InjectedconnectionFactory") private JMSContext injectedcontext. Refer to the JMS 2.0 specifications documentation.
- Supports for shared non-durable subscriptions:
- JMS 2.0 supports sharing of non-durable subscriptions. Previously, only durable subscriptions could be shared. By sharing non-durable subscriptions, multiple consumers can connect to any type of subscriptions configured to be shared. Refer to the JMS 2.0 specifications documentation.
- Delivery delay
- JMS 2.0 supports delivery delay on a message. If delivery delay is specified, JMS Provider does not deliver the messages to consumers until the delivery delay has elapsed. For more information, see send() APIs in JMSProducer and MessageProducer in JMS 2.0 specifications documentation.
- Asynchronous send
- JMS 2.0 supports sending messages asynchronously. In the previous JMS 1.1, the JMS send operation was synchronous, that is, the client side blocks the message until it receives a response from the server. In the asynchronous method of sending messages, the send method sends the message to the server and then returns control to the application without waiting for a reply from the server. Instead of being blocked unproductively while the JMS client waits for a reply, the application can engage in other useful events, such as sending or processing other messages. Whenever JMS Provider responds back with results, an appropriate method (either onCompletion or onException) of CompletionListeners interface is called. See send() APIs in JMSProducer and MessageProducer in JMS specifications documentation.
- New MDB Activation properties:
- As part of EJB 3.2 specification, the following four MDB activation configuration properties are newly added: connectionFactoryLookup, destinationLookup, clientId, and subscriptionName. WebSphere Application Server already supported the clientId and subscriptionName properties, and the support is now extended to the two new, connectionFactoryLookup and destinationLookup, properties.
- JMS Resource Definitions in Java EE applications:
- Two new annotations, javax.jms.JMSConnectionFactoryDefinition and javax.jms.JMSDestinationDefinition are supported as part of JMS 2.0 specification. These two annotations are supported in Java EE Web or EJB applications. JMSConnectionFactoryDefinition is used to configure resource javax.jms.ConnectionFactory, and JMSDestinationDefinition is used to configure the destination resource (either javax.jms.Queue or javax.jms.Topic)
JMS 2.0 behavior changes
JMS 2.0 introduces some behavior changes from the JMS 1.1 specification in Java EE 6. When we migrate our existing JMS 1.1 applications to use JMS 2.0, be aware the following behavior changes that affect some of the APIs in JMS 2.0.
Interface names Condition for exceptions JMS 1.1 JMS 2.0 Session.createDurableSubscriber ClientID is not set InvalidClientIDException IllegalStateException TopicSession.createDurableSubscriber ClientID is not set InvalidClientIDException JMSException Connection.setClientID Another connection with the same ClientID is already active IllegalStateException InvalidCliendIDException