The Java 2 Platform, Enterprise Edition (J2EE platform) is a specification for a standard server platform hosting multi-tier and thin client enterprise applications. One of the requirements of the J2EE platform is that distributed components be able to interact through reliable, asynchronous messaging. This interaction is enabled through the use of a JMS provider. In fact, Message Queue is the reference JMS implementation for the J2EE platform.
This chapter explores the ramifications of implementing JMS support in a J2EE platform environment. The chapter covers the following topics:
For additional information about using Message Queue as a JMS provider for J2EE compliant application servers, see Chapter 17, JMS Resource Adapter Property Reference, in Sun Java System Message Queue 3.7 UR1 Administration Guide.
In addition to the general JMS client programming model introduced in Chapter 2, Client Programming Model, there is a more specialized adaptation of a JMS client used in the context of J2EE platform applications. This specialized client is called a message-driven bean and is one of a family of Enterprise JavaBeans (EJB) components described in the EJB 2.0 (and later) Specification (http://java.sun.com/products/ejb/docs.html).
Message-driven beans provide asynchronous messaging; other EJB components (session beans and entity beans) can only be called synchronously, through standard EJB interfaces. However, enterprise applications often need asynchronous messaging, to allow server-side components to communicate without tying up server resources. Any application whose server-side components must respond to application events needs an EJB component that can receive and consume messages without being tightly coupled to the message producer. In enterprise applications, this capability must also scale under increasing load.
A JMS message driven bean is an EJB that implements the JMS MessageListener interface. The onMessage method (written by the MDB developer) is invoked when the MDB container receives a message. The onMessage() method consumes the message, just as the onMessage() method of a standard MessageListener object would. You do not remotely invoke methods on MDBs—as you do on other EJB components: therefore there are no home or remote interfaces associated with them. The MDB can consume messages from a single destination. The messages can be produced by standalone JMS applications, JMS components, EJB components, or Web components, as shown in Figure 5–1.
A specialized EJB container supports the MDB. It creates instances of the MDB and sets them up for asynchronous consumption of messages. The container sets up a connection with the message service (including authentication), creates a pool of sessions associated with a given destination, and manages the distribution of messages among the pooled sessions. Since the container controls the life cycle of MDB instances, it manages the pool of MDB instances to accommodate incoming message loads.
Associated with an MDB is a deployment descriptor that specifies the attributes for the connection factory and destinations used by the container in setting up message consumption. The deployment descriptor can also include other information needed by deployment tools to configure the container. Each such container supports instances of a single MDB.
In J2EE architecture, EJB containers are hosted by J2EE application servers. An application server provides resources needed by the various containers: transaction managers, persistence managers, name services, and, in the case of messaging and MDBs, a JMS provider.
In the Sun Java System Application Server, JMS messaging resources are provided by Sun Java System Message Queue:
For Sun Java System Application Server 7.0, a Message Queue messaging system is integrated into the application server as its native JMS provider.
For future releases of the Application Server, Message Queue will be plugged into the application server using standard resource adapter deployment and configuration methods.
For information about J2EE architecture, see the J2EE Platform Specification located at http://java.sun.com/j2ee/download.html#platformspec.
A resource adapter is a standardized way of plugging additional functionality into an application server that complies with J2EE 1.4. The standard, defined by the J2EE Connector Architecture (J2EECA) 1.5 specification, allows an application server to interact with external systems in a standard way. External systems can include enterprise information systems (EIS), as well as messaging systems: for example, a JMS provider. Message Queue includes a JMS resource adapter that allows application servers to use Message Queue as a JMS provider.
Plugging a JMS resource adapter into an application server allows J2EE components deployed and running in the application server to exchange JMS messages. The JMS connection factory and destination administered objects needed by these components can be created and configured using J2EE application server administration tools.
Other administrative operations, however, such as managing a broker and physical destinations, are not included in the J2EECA specification and can be performed only through provider specific tools.
The Message Queue resource adapter is integrated in the Sun J2EE 1.4 application server. However, it has not yet been certified with any other J2EE 1.4 application servers.
The Message Queue resource adapter is a single file (imqjmsra.rar) located in a directory that depends on the operating system (see Chapter 17, JMS Resource Adapter Property Reference, in Sun Java System Message Queue 3.7 UR1 Administration Guide). The imqjmsra.rar file contains the resource adapter deployment descriptor (ra.xml) as well as the JAR files needed by the application server in order to use the adapter.
You can use the Message Queue resource adapter in any J2EE-1.4-compliant application server by following the resource adapter deployment and configuration instructions that come with that application server. As commercial J2EE 1.4 application servers become available and the Message Queue resource adapter is certified for those application servers, Message Queue documentation will provide specific information on the relevant deployment and configuration procedures.