Sun Java logo     Previous      Contents      Index      Next     

Sun logo
Sun Java System Message Queue 3 2005Q1 Technical Overview 

Chapter 6
Message Queue and J2EE

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 with one another through reliable, asynchronous message exchange. 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:

Because this chapter covers both programming and deploying J2EE components, it is of interest to both application developers and administrators.


JMS/J2EE Programming: Message-Driven Beans

In addition to the general JMS client programming model introduced in JMS Programming Model, there is a more specialized adaptation of JMS used in the context of J2EE platform applications. This specialized JMS client is called a message-driven bean and is one of a family of Enterprise JavaBeans (EJB) components described in the EJB 2.0 Specification (http://java.sun.com/products/ejb/docs.html).

The need for message-driven beans arises out of the fact that other EJB components (session beans and entity beans) can only be called synchronously. These EJB components have no mechanism for receiving messages asynchronously, since they are accessed only through standard EJB interfaces.

However, asynchronous messaging is a requirement of many enterprise applications. Most such applications require that server-side components be able to communicate and respond to each other without tying up server resources. Hence the need for an EJB component that can receive messages and consume them without being tightly coupled to the producer of the message. This capability is needed for any application in which server-side components must respond to application events. In enterprise applications, this capability must also scale under increasing load.

A message-driven bean (MDB) is a specialized EJB component supported by a specialized EJB container (a software environment that provides distributed services for the components it supports).

Message-driven Bean     The MDB is a JMS message consumer 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 6-1.

Figure 6-1  Messaging with MDBs

Diagram showing JMS message producers sending messages to consuming MDB instances in a J2EE environment.

MDB Container     The MDB is supported by a specialized EJB container, responsible for creating instances of the MDB and setting them up for asynchronous consumption of messages. This involves setting up a connection with the message service (including authentication), creating a pool of sessions associated with a given destination, and managing the distribution of messages as they are received among the pool of sessions and associated MDB instances. Since the container controls the life cycle of MDB instances, it manages the pool of MDB instances so as to accommodate incoming message loads.

Associated with an MDB is a deployment descriptor that specifies the JNDI lookup names for the administered objects used by the container in setting up message consumption: a connection factory and a destination. The deployment descriptor can also include other information needed by deployment tools to configure the container. Each such container supports instances of only a single MDB.


J2EE Application Server Support

In J2EE architecture (see the J2EE Platform Specification located at http://java.sun.com/j2ee/download.html#platformspec), 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:

JMS Resource Adapter

A resource adapter is a standardized way of plugging additional functionality into an application server that complies with J2EE 1.4. (The standard is defined by the J2EE Connector Architecture (J2EECA) 1.5 specification.) This architecture allows any application server (that complies with J2EE 1.4) to interact with external systems in a standard way. External systems can include various enterprise information systems (EIS), as well as various 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.

The standard interactions facilitated by J2EECA 1.5 include connection pooling, thread pooling, transaction and security context propagation, as well as support for message-driven bean containers of various kinds. The specification also includes a standard way to create connection factories and other administered objects.

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 message server 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 the Message Queue 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 becomes certified for those application servers, Message Queue documentation will provide specific information on the relevant deployment and configuration procedures.



Previous      Contents      Index      Next     


Part No: 819-0069-10.   Copyright 2005 Sun Microsystems, Inc. All rights reserved.