J2EE Messaging
875
ClientMessage Producer
ClientMessage Consumer
Message Broker
ClientMessage
Producer and Consumer
Receive a message
Receive a message
Send a message
Send a message
There are three clients in the picture. One client is a message producer, which sends messages. Another
is a message consumer, which receives messages. There is a third client that is both a message producer
and consumer. It sends and receives messages. The broker is responsible for delivering all messages to
their correct destination.
Details of JMS
Java Message Service (JMS) is Sun's API for MOM. The interfaces defined in the JMS specification
belong to the javax.jms package. This package is part of the standard J2EE distribution.
Like other elements of J2EE, such as EJB and JSP, JMS is just an API, not an implementation. A JMS
vendor provides an implementation of the API and can also provide added features like load balancing
and clustering.
The examples in this chapter will be using BEA's WebLogic server
(http://commerce.bea.com/downloads/weblogic_server.jsp) but many other JMS products are
available. Other commercial options include Fiorano Software's FioranoMQ (http://www.fiorano.com),
Progress Software's SonicMQ (http://www.progress.com/sonicmq) and Softwired's iBus//MessageServer
(http://www.softwired-inc.com). Sun also provide two JMS implementations, JMQ
(http://www.sun.com/forte/iplanet/jmq.html) and the J2EE 1.3 beta reference server
(http://java.sun.com/j2ee).
For more information on JMS and JMS vendors take a look at Professional JMS Programming,
Wrox Press, ISBN 1-861004-93-1.
Messaging Models
There are two types of destination for JMS messages, topics and queues, which correspond to two
different messaging models, the Publish/Subscribe model and the Point-to-Point model, respectively.
Destinations are referred to as Administered objects, which are described more fully below.
The Publish/Subscribe (Pub/Sub) messaging model uses topics as its messaging destination. Topics are
configured and stored in a JNDI namespace. Clients can retrieve a reference to a topic by doing a JNDI
lookup for the topic. In the Pub/Sub model a message producer publishes messages to a particular topic.
A message consumer that subscribes to that topic will receive the message.