Vous êtes sur la page 1sur 23

SCOT

Message Driven Beans


Using JMS
Swapnil Shrivastava
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 2
Challenges with RMI-IIOP
Performance must wait while the server
performs processing

Reliability When RMI-IIOP calls the
server, it has to be running

Support for multiple senders and receivers
not possible.
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 3
Messaging
Receive messages from one or more
message producers and broadcast it to one
or more message consumers.
Support asynchronous programming.
Application
Message
Oriented
Middleware
Application
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 4
Message Oriented Middleware
Software infrastructure that supports
messaging.
Example
Sonic MQ
IBM MQSeries
BEA Tuxedo/Q
Microsoft MSMQ
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 5
Challenges addressed
Performance A messaging client does not need
to block when performing a request.
Reliability If your MOM supports guaranteed
delivery , you can send a message and know for
sure it will reach the destination, even if the
consumer is not available.
Support for multiple senders and receivers
possible..
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 6
Messaging Domains
It is the style of messaging which is chosen
to send messages.
Types :
Publish/Subscribe (Pub/Sub) Domain.
Point-to-Point (PTP) Domain.
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 7
Publish/Subscribe
Many message producers talking to many message
consumers.
It is an implementation of distributed event driven
processing model.
Publisher send messages to topic in JMS.
Consumers who are interested in message
subscribe to message topic.
Topic are persistent stores located at JMS
destination.
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 8
Publish/Subscribe
Producer1
Producer 2
Consumer 2
Consumer 1
Topic

subscribe
deliver
subscribe
deliver
publishes
publishes
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 9
Point-to-Point
Single consumer for each message.
Multiple producers can send messages to
the queue but each message is delivered to
single consumer.
Messages are sent to queue from which they
are distributed to consumers in FIFO order.
Queue are persistent stores located at JMS
destination.
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 10
Point-to-Point
Producer Consumer
sends
acknowledges
consumes
Queue
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 11
JMS
JMS is a messaging standard.
Allows applications to create,send ,receive and
read messages.
JMS consists of
JMS API : to write code to send and receive messages.
JMS SPI : where we plug in JMS drivers.
Low level topology issues are abstracted from the
developer.
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 12
JMS Programming Model
Locate JMS driver.
Create a JMS connection.
Create a JMS Session.
Locate a JMS destination.
Create a JMS producer or a JMS consumer.
Send or receive your message.

SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 13
JMS Architecture
Connection
Factory
Connection Session
Message
Consumer
Message
Producer
Message
Queue
or Topic
Queue
or Topic
creates
creates
creates
creates
creates
Sends to
Gets
from
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 14
JMS-EJB Integration
To allow EJB components to benefit from
value propositions of messaging such as
Non blocking clients
N-ary communication
EJB 2.0 introduced Message Driven Beans
for JMS-EJB Integration.
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 15
Message Driven Beans
MDB is a special EJB component that can
receive JMS messages.
MDB consumes messages from queues or
topics that are sent by any valid JMS client.
JMS API is used to send messages to MDB.
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 16
Message Driven
Bean Instance
Client
JMS Destination
Message Driven
Bean Pool
Send/
publishes
EJB Server
Message Driven Beans
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 17
MDB Characteristics
Doesnt have home interface, remote
interface,local interface and local home
interface.
Have one loosely typed business method.
Do not have any return values.
Cannot send exceptions back to the client.
They are stateless.
Can be durable or non durable subscribers.
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 18
Message Driven Bean Interface
public interface javax.jms.MessageListener
{
public void onMessage(Message message);
}

public interface javax.ejb.MessageDrivenBean extends EnterpriseBean
{
public void ejbRemove()throws EJBException;
public void setMessageDrivenContext(MessageDrivenContext ctx)
throws EJBException;
}
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 19
MDB Ingredients
Message Driven Beans implements both
MessageDrivenBean and MessageListener
interface.
Consistes of:
MessageDrivenBean class.
Deployment Descriptor.
Vendor Specific Files.
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 20
Example
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 21
MDB Object Model
<<interface>>
java.io.Serializable
<<interface>>
javax.ejb.EnterpriseBean
<<interface>>
javax.ejb.MessageDrivenBean
Bean Implement
Class
Comes with Java2 platform
Comes with EJB Distribution
Written by developer
<<interface>>
javax.jms.MessageListener
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 22
Message Driven Bean Life Cycle
Does Not Exist
Pooled
1: newInstance()
2: setMessageDrivenContext()
3: ejbCreate()
ejbRemove()
onMessage()
SCOT
Message Driven Bean (c)CDAC(Formerly NCST) 23
References
Mastering Enterprise Java Beans
J2EE 1.4 Tutorials
Professional Java Server Programming,
J2EE Edition

Vous aimerez peut-être aussi