Get the message: The message in Java EE 1.4

Source: Internet
Author: User

In this article, I will outline the changes required to support the message introduced in the 1.4 Java EE specification. I will specifically analyze the requirements for JMS 1.1 and the new restrictions that are used, the new concepts associated with message objectives, and the significant changes that the EJB Spec 2.1 version brings to message-driven beans. These are particularly useful for developers and managers who are familiar with the messages in Java EE 1.3 and want to write new applications or migrate existing messaging applications to an application server that is compatible with Java EE 1.4.

JMS 1.1

The Java-compliant application server now needs to support the 1.1 version of the Java-based messaging Service (Java message SERVER,JMS) specification, which may be the most obvious change in the new version of EE specification. JMS 1.1 is fully backwards compatible with the JMS 1.1 required by the Java EE 1.3 specification, so there should be no need to change existing applications. JMS 1.1 introduced the Unified Messaging domain, which was discussed in detail in this article by Bobby Woolf. It is worth emphasizing that, unless backward compatibility is required, there is no reason to write new JMS applications with old queues and subject interfaces. The new application should use only the new unified interface, as the example in Listing 1 shows.

Listing 1. Show examples of unified JMS interfaces

InitialContext context = new InitialContext();
ConnectionFactory factory =
(ConnectionFactory) context.lookup("java:comp/env/jms/cf");
Destination source =
(Destination) context.lookup("java:comp/env/jms/source");
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(source);
Message message = consumer.receive();
connection.close();

As Bobby put it in his article, the unified interface not only simplifies the messaging programming model, it also enables applications to receive messages from queues with a transaction session, and to send messages to the subject (or vice versa). This means that you can send and receive in the same transactional unit of work without the help of a bean or container-managed transaction.

Java EE restrictions on the use of JMS

Like the previous version of the Java EE Specification, version 1.4 has some limitations on the use of JMS. I will analyze these limitations in this section.

Restricted interfaces

While many developers may not know, the Java EE specification always has some limitations on how Java applications use the JMS API. For example, the following interfaces are used for integration between JMS providers and application servers (which are part of the application server facilities described in the JMS specification) and are therefore not used by applications:

Javax.jms.ServerSession

Javax.jms.ServerSessionPool

Javax.jms.ConnectionConsumer

All Javax.jms.XA Interfaces

Methods of restriction

The Java EE 1.3 specification gives a confusing statement about methods that "application components cannot execute in a container that prevents the creation of threads." The EJB container does not allow the application to create threads, but a WEB container can allow the application to do so. As a result, in Java EE 1.3, you can call or not call these methods, depending on the Web container you are using. Fortunately, the Java EE 1.4 specification removes these confusing assertions, except that the following methods can only be used by applications running in the client container-in other words, they are not invoked in the Web or EJB container:

javax.jms.ServerSession method setMessageListener()
javax.jms.ServerSession method getMessageListener()
javax.jms.Session method run()
javax.jms.QueueConnection method createConnectionConsumer()
javax.jms.TopicConnection method createConnectionConsumer()
javax.jms.TopicConnection method createDurableConnectionConsumer()
javax.jms.MessageConsumer method getMessageListener()
javax.jms.MessageConsumer method setMessageListener()
javax.jms.Connection method setExceptionListener()
javax.jms.Connection method stop()
javax.jms.Connection method setClientID()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.