JMS Chat Sample Application
Table of Contents
Overview of the Sample Application
|
JMS (Java
Messaging Service) is a strategic technology for J2EE. JMS works in
concert with other technologies to provide reliable, asynchronous communication
between components in a distributed computing environment. Enterprise messaging
is now recognized as an essential mechanism for building enterprise applications.
By combining Java technology with enterprise messaging, the JMS API provides
a new, powerful tool for solving enterprise computing problems.
The OC4J JMS provider allows the user to choose either in-memory or file system based message persistence.
This sample application demonstrates the use of in-memory queues which are configured in jms.xml.
An MDB (Message Driven Bean) is a stateless, server-side,
transaction-aware component that is driven by a Java message (javax.jms.Message).
It is invoked by the EJB Container when a message is received from a JMS
Queue or Topic. It acts as a simple message listener.
This sample application demonstrates the features
and usage of in-memory JMS queues and MDB. The sample uses the scenario
of a Chat Application for demonstrating these features. Using this application,
a user can login to a Chat Room and send/receive messages to/from other
registered users.
The sample application consists to two components.
They are described as follows :
-
Server Component : This component is an ear file and runs on OC4J. It constitutes
of two servlets (for receiving and sending messages) and an MDB (for listening
to the enqueued messages). Any operation on the queue (single receiver)
or the topic (multiple receiver) can be done through the classes present
in this component.
-
Client Component : This component is a jar file and constitutes of Java
classes that generate a swing interface to help the logged in user to chat
with other registered users. When the user first starts the application,
then he/she will see the following screen
Through this window, the user specifies where the Chat Server is running.
The user also specifies the ChatID that he/she is going to use. If you have
previously logged into the application, then the application will remember
your ChatID. In this case, please select I am an existing user. The application
will remember the ChatID until the OC4J server is restarted. Please note
that the UI of the window may change according to the system settings.
After he/she has successfully registered the ChatID on the Chat Server,
then the following window will appear.
The User will now chat through this window. All the messages from
other users will appear on the top TextArea. The User can send a message
to other users by typing it in the bottom TextArea and then pressing the
Send button or by pressing the Return key on the keyboard.
The application also stores offline messages. This means that if a registered
client is not active and there is some chatting going on during this time,
then this user will receive all the messages when he/she logs in the next
time. The messages will be stored in the server till either all the subscribers
have received it or the server restarts.
Please refer to Installing
the sample for step-by-step instructions on extracting the files, deploying
and running the application successfully.
The directory structure of the deliverable JMSChatSample.jar
is as shown below. Please note that the important files for the JMS
functionality are located on the server; namely the files SendMessage.java,
GetMessage.java, ChatSubscriber.java and ListenerMBDBean.java.
| Directory |
Files |
Description |
| ChatSample\doc |
Readme.html |
This file |
| Install.html |
This file has instructions required to
install and deploy the sample application. |
| ChatSample\server\Chat\src\oracle\otnsamples\oc4jjms |
SendMessage.java |
This Servlet is used by the
Chat Client to send the message. |
| GetMessage.java |
This Servlet is used by the
Chat Client to receive a message. |
| ChatSubscriber.java |
This Java class has the important
methods for adding a subscriber and dequeing the message. The methods in
this class are used by the GetMessage.java servlet. |
| ChatSample\server\Chat\src\oracle\otnsamples\oc4jjms\impl |
ListenerMDBBean.java |
This MDB listens to the messages sent
by the Chat Clients. |
| ChatSample\client\src\oracle\otnsamples\oc4jjms |
All Java Files |
These files together constitute the Client
Swing Application to access the Chat Server. |
|