Message Driven Beans
Message driven beans are the light weight components used for
communication. In
message driven beans the messaging service is in asynchronous mode because the
user is not intended to get the instant result. To understand the concept of
message driven beans more clearly first we should go through the various concepts
illustrated given below: Motivations for messaging: EJB components are
used to develop the applications for the distributed computing network.
Distributed computing network uses the RMI-IIOP protocol to communicate with
each other. This protocol is used to call the EJB components. RMI-IIOP accepts challenges in several areas like: There are four previous concerns that the messaging
addresses with RMI-IIOP as follows:
Non blocking request processing: There is no
need to block the messaging request while executing another request. For example
suppose you are purchasing a book from Amazon.com having a single click
functionality. you are enable to continue browsing the site without waiting to
check the authorization of your credit card. Until and unless there is something
wrong Amazon.com sends you a confirmation email. These types of systems are
developed by using the messaging technique. Decoupling: In case of
message-oriented-middleware, it is not necessary for the sender to have the
knowledge about the message receiver. It only interacts with the messaging
system while sending messages. Thus the message senders are decoupled from
consumers. Reliability: Your message-oriented-middleware
guarantees to send a message to its destination if the receiver is not
temporarily available, simply by sending the message to the
message-oriented-middleware which sends the message to the receiver when he is
available. While it is not possible with RMI-IIOP protocol because there is no
middleman in this case. If you send a message using the RMI-IIOP protocol and if
server is down then it throws the exception.
Support for multiple senders and receivers: Most
of the message-oriented-middleware supports this features i.e. receiving
messages from multiple senders and can also broadcast them to many receivers. Message-oriented-middleware is the term that can be given
to any system that supports the messaging system. There are a number of products
based on MOM architecture. BEA Tuxedo/Q, Sun Java System Messaging Server,
IBM WebSphere MQ, Tibco Rendezevous, Microsoft MSMQ, FioranoMQ and Sonic
Software SonicMQ are the examples of MOM based architecture. Java Message Services (JMS): JMS API is an
enterprise tool developed by Sun Microsystems used to develop the enterprise
applications. JMS API supports to a framework that allows the development of
portable and message based applications. JMS communicates in synchronous or in
asynchronous mode by using point-to-point and the publish-subscribe models
respectively. JMS
has become vendor specific and many vendors such as IBM, Oracle, Hewlett-Packard, BEA Systems and
Macromedia are providing the JMS implementation.
JMS API: JMS APIs play an important role as
comparing the RMI-IIOP protocol. You need to aware with different interfaces,
low level topology issues like structure, messaging format, networking protocol
and server location. All the points described above are applicable to both
point-to-point as well as publish/subscribe. Here we are going to discuss JMS by taking the queuing
system. Queuing system includes the following parts:
JMS Architecture: Talk first about
JMS while talking about the message driven beans. There are a lot of
messaging systems exist in the market. Messaging systems provide a mechanism to
exchange data and events asynchronously. JMS API defines a standard way to
access any messaging system such as JDBC that enables the user to talk to SQL Server,
Oracle and Sybase simply by using the same API. The additional benefits of JMS
API are loose coupling between the generated request and the code that services
the request. Here are some of the basics of the messaging server
that one should know to more clearly understand the concept of JMS APIs: Messaging Domains: A messaging system includes
several models of operation. JMS API provides separate domains
corresponding to different models. JMS provider is free to implement one or more
domains. Point-to-Point and Publish/Subscribe are the two most commonly used
domains. These two domains concludes the following concepts.
Point-to-Point (PTP): An application that uses
the point-to-point technique for messaging has the following characteristics. A call center application is the example of a PTP
domain, where a phone call enters in the queue therefore only one operator takes
care of this call rather than all of the operators. Publish/Subscribe (pub/sub): An application that
uses the pub/sub technique must include the following characteristics.
An email newsletter application may use the pub/sub
model, where an interested candidate may become the subscriber to receive a new
published message. Integrating JMS with EJB: Integration of JMS
with EJB is the excellent idea because of it the EJB components gets benefit
from the value proposed by messaging like multinary communications and non
blocking clients. The idea behind the introduction of new type of bean is to
consume messages in an EJB application. Use a Java Object that receives the JMS messages
to call an EJB client: Instead of developing the whole new bean the java
community proposed an idea of object to receive a message and to call the
appropriate EJB component such as the session bean or the entity bean. But
the problems that come with this approach are:
Reuse an existing type of EJB component somehow to
receive JMS messages: Session beans or entity beans may receive messages but
the problem with this approach is: Message driven bean: Message driven beans are
the special type of components that can receive the JMS as well as
other type of messages. Message driven bean can also be used to receive the
messages other than JMS. When a message is reached at the destination then the
EJB container invokes the message driven bean. A message driven bean is
decoupled with the client that sends the message. A client is not allowed to
access the message driven bean through a business interface. The client can interact with the message driven bean only through the messaging system.
To interact with the message driven bean use the message provider specific API such as JMS.
