Java Reference
In-Depth Information
In this chapter, you will combine
JMX
technology with the Java Message Service
(
JMS
).
JMS
is part of the
J2EE
platform and provides enterprise messaging for
J2EE
applications. This chapter uses a simple example to show how you can add func-
tionality to
JMS
applications using MBeans. In addition, the example shows how
MBeans can give you a view into the messaging of a
JMS
application for diagnostics
and management.
13.1
T
he Java Message Service
Enterprise messaging is an essential tool for building enterprise applications. It
provides a standard way for applications to communicate in an asynchronous
fashion.
JMS
supports two models of messaging: Point-to-Point and Publish-
Subscribe. Point-to-Point messaging lets a sender send a message to a single
recipient, whereas Publish-Subscribe allows a sender to “broadcast” a message to
several recipients. In both cases, the message sender and message receiver behave
in an asynchronous manner, meaning that the receiver does not necessarily have
to be present when the message is sent.
In the Point-to-Point model, the message is queued for later consumption. In
Publish-Subscribe mode, a consumer can choose two different types of subscrip-
tion. A
durable
subscription ensures a consumer will receive all messages that are
published, because all published messages will be queued by the
JMS
provider
until retrieved. Alternatively, with a
normal
subscription, the subscriber must be
present and subscribed to receive published messages. In this chapter, we will use
Publish-Subscribe with a normal subscription.
In Publish-Subscribe mode, applications observe
topics.
A topic is the destina-
tion for a set of messages.
JMS
clients publish and/or subscribe to a particular
topic for message connectivity.
JMS
implementations adhere to the interfaces defined in the
J2EE
platform.
When developing
JMS
applications, you write your code according to the inter-
faces. The only difference between
JMS
implementations is the way you deploy
www.javasoft.com.)
13.2 Combining JMX with JMS
Combining
JMS
and
JMX
opens many possibilities for Java applications. Using
JMS
, you can transform your management system so that it acts as a driver for
your applications. It can also receive messages indicating the health of an