Developing Message-Driven Beans; Description Of A Message-Driven Bean; Developing A Message-Driven Bean - Red Hat APPLICATION SERVER - JONAS Manual

Jonas
Hide thumbs Also See for APPLICATION SERVER - JONAS:
Table of Contents

Advertisement

The EJB 2.1 specification defines a new kind of EJB component for receiving asynchronous messages.
This implements some type of "asynchronous EJB component method invocation" mechanism. The
Message-Driven Bean (also referred to as MDB in the following) is an Enterprise JavaBean, not an
Entity Bean or a Session Bean, that plays the role of a JMS MessageListener.
The EJB 2.1 specification contains detailed information about MDB. The Java Message Service Spec-
ification 1.1 contains detailed information about JMS. This chapter focuses on the use of Message-
Driven Beans within the JOnAS server.

9.1. Description of a Message-Driven Bean

A Message-Driven Bean is an EJB component that can be considered as a JMS
MessageListener, that is, processing JMS messages asynchronously; it implements the
onMessage(javax.jms.Message)
interface. It is associated with a JMS destination, that is, a Queue for "point-to-point" messaging or a
Topic for "publish/subscribe." The
client application to the corresponding JMS destination. It is possible to associate a JMS message
selector to filter the messages that the Message-Driven Bean should receive.
JMS messages do not carry any context, thus the
transactional context. However, a new transaction can be initiated at this moment (refer to Section
9.5 Transactional Aspects for more details). The
MDB itself or on other beans, and can involve other resources by accessing databases or by sending
messages. Such resources are accessed the same way as for other beans (entity or session), that is,
through resource references declared in the deployment descriptor.
The JOnAS container maintains a pool of MDB instances, allowing large volumes of messages to be
processed concurrently. An MDB is similar in some ways to a stateless Session Bean: its instances are
relatively short-lived, it retains no state for a specific client, and several instances may be running at
the same time.

9.2. Developing a Message-Driven Bean

The
MDB
class
javax.ejb.MessageDrivenBean
must be implemented:
A public constructor with no argument.
public void ejbCreate()
be used to allocate some resources, such as connection factories, for example if the bean sends
messages, or datasources or if the bean accesses databases.
public void ejbRemove()
method.
public void setMessageDrivenContext(MessageDrivenContext mdc)
container after the instance creation, with no transaction context. The JOnAS container provides
the bean with a container context that can be used for transaction management, for example, for
calling
setRollbackOnly(), getRollbackOnly(), getUserTransaction()
The following is an example of an MDB class:

Developing Message-Driven Beans

method, defined in the
onMessage
must
implement
interfaces. In addition to the
: with no arguments, called at the bean-instantiation time. It may
: usually used to free the resources allocated in the ejbCreate
method is activated on receipt of messages sent by a
method will execute without pre-existing
onMessage
method can call other methods on the
onMessage
the
javax.jms.MessageListener
onMessage
Chapter 9.
javax.jms.MessageListener
method, the following
: called by the
and
the
.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the APPLICATION SERVER - JONAS and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Application server

Table of Contents