A Jms Ejb Example - Red Hat APPLICATION SERVER - JONAS Manual

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

Advertisement

Chapter 26. JMS User's Guide
26.5.2. Accessing the Message-Oriented Middleware as a J2EE1.4 Adapter
With JOnAS, a JMS server can be accessed through a resource adapter that can be deployed.
To deploy such a resource adapter, put the corresponding archive file (
directory, declare it at the end of the
rars/autoload
manually through the
Configuring and deploying such adapters is explained in Section 3.7 Configuring JMS Resource
Adapters.

26.6. A JMS EJB Example

This example shows an EJB application that combines an Enterprise Bean sending a JMS message
and an Enterprise Bean writing a Database (an Entity Bean) within the same global transaction. It is
composed of the following elements:
A Session Bean, EjbComp, with a method for sending a message to a JMS topic.
An Entity Bean, Account (the one used in the sample eb with container-managed persistence),
which writes its data into a relational database table and is intended to represent a sent message
(that is, each time the EjbComp bean sends a message, an Entity Bean instance will be created).
An EJB client, EjbCompClient, which calls the sendMsg method of the EjbComp bean and creates
an Account entity bean, both within the same transaction. For a transaction commit, the JMS mes-
sage is actually sent and the record corresponding to the entity bean in the database is created. For
a rollback, the message is not sent and nothing is created in the database.
A pure JMS client MsgReceptor, outside the JOnAS server, the role of which is to receive the
messages sent by the Enterprise Bean on the topic.
You can find the sample JMS application in $JONAS_ROOT/examples/src/jms/; it is described in
Section 26.6 A JMS EJB Example.
26.6.1. The Session Bean Performing JMS Operations
The bean should contain code for initializing the references to JMS administered objects that it will
use. To avoid repeating this code in each method performing JMS operations, it can be introduced in
the
method.
ejbCreate
public class EjbCompBean implements SessionBean {
...
ConnectionFactory cf = null;
Topic topic = null;
public void ejbCreate() {
....
ictx = new InitialContext();
cf = (ConnectionFactory)
ictx.lookup("java:comp/env/jms/conFactSender");
topic = (Topic) ictx.lookup("java:comp/env/jms/topiclistener");
}
...
}
All code that is not necessary for understanding the JMS logic (such as exception management) has
been removed from the above example.
tool.
jonasAdmin
*.rar
jonas.properties
207
) in JOnAS's
file, or deploy it

Advertisement

Table of Contents
loading

This manual is also suitable for:

Application server

Table of Contents